static int open_restricted(const char *path, int flags, void *user_data) { /* for test devices we don't expect this to be called */ ck_abort(); return 0; }
END_TEST #endif /* __GNUC__ */ START_TEST(test_ck_abort) { ck_abort(); #define LINENO_ck_abort _STR(__LINE__) }
void test_logfunc_abort_on_error(enum libevdev_log_priority priority, void *data, const char *file, int line, const char *func, const char *format, va_list args) { vprintf(format, args); ck_abort(); }
void __free(void *buffer) { free_called += 1; if (testcase == 2) { ck_assert(buffer == malloc_b2); return; } ck_abort(); }
static void func(pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) { time_t now; time(&now); if ((now - start) >= 30) { m->quit(m, 1); fprintf(stderr, "Test failed\n"); ck_abort(); } else raise(SIGUSR1); }
static void ocdb_logger_setup(void) { enum MAPISTATUS mapi_status; struct openchangedb_context *backend_ctx = NULL; mem_ctx = talloc_new(NULL); mapi_status = mock_backend_init(mem_ctx, &backend_ctx); if (mapi_status != MAPI_E_SUCCESS) { fprintf(stderr, "Failed to initialize Mocked backend %d\n", mapi_status); ck_abort(); } mapi_status = openchangedb_logger_initialize(mem_ctx, 1, ">>> ", backend_ctx, &oc_ctx); if (mapi_status != MAPI_E_SUCCESS) { fprintf(stderr, "Failed to initialize Logger backend %d\n", mapi_status); ck_abort(); } ZERO_STRUCT(functions_called); }
static void ldb_setup(void) { int ret; create_ldb_from_ldif(OPENCHANGEDB_LDB, OPENCHANGEDB_SAMPLE_LDIF, LDB_DEFAULT_CONTEXT, LDB_ROOT_CONTEXT); g_mem_ctx = talloc_new(talloc_autofree_context()); ret = openchangedb_ldb_initialize(g_mem_ctx, RESOURCES_DIR, &g_oc_ctx); if (ret != MAPI_E_SUCCESS) { fprintf(stderr, "Error initializing openchangedb %d\n", ret); ck_abort(); } }
/* This is called whenever the context status changes */ static void context_state_callback(pa_context *c, void *userdata) { fail_unless(c != NULL); switch (pa_context_get_state(c)) { case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; case PA_CONTEXT_READY: { int i; fprintf(stderr, "Connection established.\n"); for (i = 0; i < NSTREAMS; i++) { char name[64]; pa_format_info *formats[1]; formats[0] = pa_format_info_new(); formats[0]->encoding = PA_ENCODING_PCM; pa_format_info_set_sample_format(formats[0], PA_SAMPLE_FLOAT32); pa_format_info_set_rate(formats[0], SAMPLE_HZ); pa_format_info_set_channels(formats[0], 1); fprintf(stderr, "Creating stream %i\n", i); snprintf(name, sizeof(name), "stream #%i", i); streams[i] = pa_stream_new_extended(c, name, formats, 1, NULL); fail_unless(streams[i] != NULL); pa_stream_set_state_callback(streams[i], stream_state_callback, (void*) (long) i); pa_stream_connect_playback(streams[i], NULL, &buffer_attr, PA_STREAM_START_CORKED, NULL, i == 0 ? NULL : streams[0]); pa_format_info_free(formats[0]); } break; } case PA_CONTEXT_TERMINATED: mainloop_api->quit(mainloop_api, 0); break; case PA_CONTEXT_FAILED: default: fprintf(stderr, "Context error: %s\n", pa_strerror(pa_context_errno(c))); ck_abort(); } }
long __ftell(FILE *fd) { ftell_called += 1; if (testcase == 2) { ck_assert(fd == ref_fd); return not_offset; } if (testcase == 3) { ck_assert(fd == ref_fd); return not_offset; } ck_abort(); return 0; }
END_TEST START_TEST(path_add_invalid_path) { struct libinput *li; struct libinput_event *event; struct libinput_device *device; li = litest_create_context(); device = libinput_path_add_device(li, "/tmp/"); ck_assert(device == NULL); libinput_dispatch(li); while ((event = libinput_get_event(li))) ck_abort(); libinput_unref(li); }
void *__malloc(size_t size) { malloc_called += 1; if (testcase == 1) { return NULL; } if (testcase == 2) { ck_assert(size == ref_size); return malloc_b2; } if (testcase == 3) { ck_assert(size == ref_size); return malloc_b3; } ck_abort(); return NULL; }
static void _httpc_free(struct httpc *hc) { hc->th_run = FALSE; g_thread_join(hc->th); hc->th = NULL; close(hc->polling); hc->polling = -1; close(hc->waiting); hc->waiting = -1; if (g_async_queue_length(hc->aq) != 0) { guint i; guint len = g_async_queue_length(hc->aq); GString *buff = qev_buffer_get(); for (i = 0; i < len; i++) { gchar *msg = g_async_queue_pop(hc->aq); g_string_append_printf(buff, "\t* %s\n", msg); } CRITICAL("Async Queue was not emptied; %u messages remain:\n%s", len, buff->str); qev_buffer_put(buff); ck_abort(); } g_async_queue_unref(hc->aq); hc->aq = NULL; g_free(hc->sid); hc->sid = NULL; g_mutex_clear(&hc->lock); g_slice_free1(sizeof(*hc), hc); }
static void _do(const gchar *cfg) { gboolean die = FALSE; if (!g_file_set_contents("test_config.ini", cfg, strlen(cfg), NULL)) { goto abort; } test_setup_with_config("test_config.ini"); out: unlink("test_config.ini"); if (die) { ck_abort(); } return; abort: die = TRUE; goto out; }
/* This routine is called whenever the stream state changes */ static void stream_state_callback(pa_stream *s, void *userdata) { fail_unless(s != NULL); switch (pa_stream_get_state(s)) { case PA_STREAM_UNCONNECTED: case PA_STREAM_CREATING: case PA_STREAM_TERMINATED: break; case PA_STREAM_READY: { int r, i = (int) (long) userdata; fprintf(stderr, "Writing data to stream %i.\n", i); r = pa_stream_write(s, data, sizeof(data), nop_free_cb, (int64_t) sizeof(data) * (int64_t) i, PA_SEEK_ABSOLUTE); fail_unless(r == 0); /* Be notified when this stream is drained */ pa_stream_set_underflow_callback(s, underflow_cb, userdata); /* All streams have been set up, let's go! */ if (++n_streams_ready >= NSTREAMS) { fprintf(stderr, "Uncorking\n"); pa_operation_unref(pa_stream_cork(s, 0, NULL, NULL)); } break; } default: case PA_STREAM_FAILED: fprintf(stderr, "Stream error: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s)))); ck_abort(); } }
/* This is called whenever the context status changes */ static void context_state_callback(pa_context *c, void *userdata) { fail_unless(c != NULL); switch (pa_context_get_state(c)) { case PA_CONTEXT_CONNECTING: case PA_CONTEXT_AUTHORIZING: case PA_CONTEXT_SETTING_NAME: break; case PA_CONTEXT_READY: { pa_stream_flags_t flags = PA_STREAM_AUTO_TIMING_UPDATE; pa_buffer_attr attr; static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, .rate = 44100, .channels = 2 }; pa_zero(attr); attr.maxlength = (uint32_t) -1; attr.tlength = latency > 0 ? (uint32_t) pa_usec_to_bytes(latency, &ss) : (uint32_t) -1; attr.prebuf = (uint32_t) -1; attr.minreq = (uint32_t) -1; attr.fragsize = (uint32_t) -1; #ifdef INTERPOLATE flags |= PA_STREAM_INTERPOLATE_TIMING; #endif if (latency > 0) flags |= PA_STREAM_ADJUST_LATENCY; pa_log("Connection established"); stream = pa_stream_new(c, "interpol-test", &ss, NULL); fail_unless(stream != NULL); if (playback) { pa_assert_se(pa_stream_connect_playback(stream, NULL, &attr, flags, NULL, NULL) == 0); pa_stream_set_write_callback(stream, stream_write_cb, NULL); } else { pa_assert_se(pa_stream_connect_record(stream, NULL, &attr, flags) == 0); pa_stream_set_read_callback(stream, stream_read_cb, NULL); } pa_stream_set_latency_update_callback(stream, stream_latency_cb, NULL); break; } case PA_CONTEXT_TERMINATED: break; case PA_CONTEXT_FAILED: default: pa_log_error("Context error: %s", pa_strerror(pa_context_errno(c))); ck_abort(); } } START_TEST (interpol_test) { pa_threaded_mainloop* m = NULL; int k; struct timeval start, last_info = { 0, 0 }; pa_usec_t old_t = 0, old_rtc = 0; #ifdef CORK bool corked = false; #endif /* Set up a new main loop */ m = pa_threaded_mainloop_new(); fail_unless(m != NULL); mainloop_api = pa_threaded_mainloop_get_api(m); fail_unless(mainloop_api != NULL); context = pa_context_new(mainloop_api, bname); fail_unless(context != NULL); pa_context_set_state_callback(context, context_state_callback, NULL); fail_unless(pa_context_connect(context, NULL, 0, NULL) >= 0); pa_gettimeofday(&start); fail_unless(pa_threaded_mainloop_start(m) >= 0); /* #ifdef CORK */ for (k = 0; k < 20000; k++) /* #else */ /* for (k = 0; k < 2000; k++) */ /* #endif */ { bool success = false, changed = false; pa_usec_t t, rtc, d; struct timeval now, tv; bool playing = false; pa_threaded_mainloop_lock(m); if (stream) { const pa_timing_info *info; if (pa_stream_get_time(stream, &t) >= 0 && pa_stream_get_latency(stream, &d, NULL) >= 0) success = true; if ((info = pa_stream_get_timing_info(stream))) { if (memcmp(&last_info, &info->timestamp, sizeof(struct timeval))) { changed = true; last_info = info->timestamp; } if (info->playing) playing = true; } } pa_threaded_mainloop_unlock(m); pa_gettimeofday(&now); if (success) { #ifdef CORK bool cork_now; #endif rtc = pa_timeval_diff(&now, &start); pa_log_info("%i\t%llu\t%llu\t%llu\t%llu\t%lli\t%u\t%u\t%llu\t%llu\n", k, (unsigned long long) rtc, (unsigned long long) t, (unsigned long long) (rtc-old_rtc), (unsigned long long) (t-old_t), (signed long long) rtc - (signed long long) t, changed, playing, (unsigned long long) latency, (unsigned long long) d); fflush(stdout); old_t = t; old_rtc = rtc; #ifdef CORK cork_now = (rtc / (2*PA_USEC_PER_SEC)) % 2 == 1; if (corked != cork_now) { pa_threaded_mainloop_lock(m); pa_operation_unref(pa_stream_cork(stream, cork_now, NULL, NULL)); pa_threaded_mainloop_unlock(m); pa_log(cork_now ? "Corking" : "Uncorking"); corked = cork_now; } #endif } /* Spin loop, ugly but normal usleep() is just too badly grained */ tv = now; while (pa_timeval_diff(pa_gettimeofday(&now), &tv) < 1000) pa_thread_yield(); } if (m) pa_threaded_mainloop_stop(m); if (stream) { pa_stream_disconnect(stream); pa_stream_unref(stream); } if (context) { pa_context_disconnect(context); pa_context_unref(context); } if (m) pa_threaded_mainloop_free(m); } END_TEST int main(int argc, char *argv[]) { int failed = 0; Suite *s; TCase *tc; SRunner *sr; if (!getenv("MAKE_CHECK")) pa_log_set_level(PA_LOG_DEBUG); bname = argv[0]; playback = argc <= 1 || !pa_streq(argv[1], "-r"); latency = (argc >= 2 && !pa_streq(argv[1], "-r")) ? atoi(argv[1]) : (argc >= 3 ? atoi(argv[2]) : 0); s = suite_create("Interpol"); tc = tcase_create("interpol"); tcase_add_test(tc, interpol_test); tcase_set_timeout(tc, 5 * 60); suite_add_tcase(s, tc); sr = srunner_create(s); srunner_run_all(sr, CK_NORMAL); failed = srunner_ntests_failed(sr); srunner_free(sr); return (failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }
END_TEST START_TEST(path_add_device_suspend_resume_fail) { struct libinput *li; struct libinput_device *device; struct libinput_event *event; struct libevdev_uinput *uinput1, *uinput2; int rc; int nevents; void *userdata = &rc; uinput1 = litest_create_uinput_device("test device", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); uinput2 = litest_create_uinput_device("test device 2", NULL, EV_KEY, BTN_LEFT, EV_KEY, BTN_RIGHT, EV_REL, REL_X, EV_REL, REL_Y, -1); li = libinput_path_create_context(&simple_interface, userdata); ck_assert(li != NULL); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput1)); ck_assert(device != NULL); device = libinput_path_add_device(li, libevdev_uinput_get_devnode(uinput2)); ck_assert(device != NULL); libinput_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_ADDED); libinput_event_destroy(event); nevents++; } ck_assert_int_eq(nevents, 2); libinput_suspend(li); libinput_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); ck_assert_int_eq(type, LIBINPUT_EVENT_DEVICE_REMOVED); libinput_event_destroy(event); nevents++; } ck_assert_int_eq(nevents, 2); /* now drop one of the devices */ libevdev_uinput_destroy(uinput1); rc = libinput_resume(li); ck_assert_int_eq(rc, -1); libinput_dispatch(li); nevents = 0; while ((event = libinput_get_event(li))) { enum libinput_event_type type; type = libinput_event_get_type(event); /* We expect one device being added, second one fails, * causing a removed event for the first one */ if (type != LIBINPUT_EVENT_DEVICE_ADDED && type != LIBINPUT_EVENT_DEVICE_REMOVED) ck_abort(); libinput_event_destroy(event); nevents++; } ck_assert_int_eq(nevents, 2); libevdev_uinput_destroy(uinput2); libinput_unref(li); open_func_count = 0; close_func_count = 0; }
END_TEST START_TEST (test_send_cdpv2) { int n; /* Packet we should build: IEEE 802.3 Ethernet Destination: CDP/VTP/DTP/PAgP/UDLD (01:00:0c:cc:cc:cc) Source: 5e:10:8e:e7:84:ad (5e:10:8e:e7:84:ad) the factory default) Length: 111 Logical-Link Control DSAP: SNAP (0xaa) IG Bit: Individual SSAP: SNAP (0xaa) CR Bit: Command Control field: U, func=UI (0x03) 000. 00.. = Command: Unnumbered Information (0x00) .... ..11 = Frame type: Unnumbered frame (0x03) Organization Code: Cisco (0x00000c) PID: CDP (0x2000) Cisco Discovery Protocol Version: 2 TTL: 180 seconds Checksum: 0x5926 [correct] [Good: True] [Bad : False] Device ID: Second chassis Type: Device ID (0x0001) Length: 18 Device ID: Second chassis Addresses Type: Addresses (0x0002) Length: 26 Number of addresses: 2 IP address: 172.17.142.36 Protocol type: NLPID Protocol length: 1 Protocol: IP Address length: 4 IP address: 172.17.142.36 IP address: 172.17.142.38 Protocol type: NLPID Protocol length: 1 Protocol: IP Address length: 4 IP address: 172.17.142.38 Port ID: Gigabit Ethernet 5/8 Type: Port ID (0x0003) Length: 24 Sent through Interface: Gigabit Ethernet 5/8 Capabilities Type: Capabilities (0x0004) Length: 8 Capabilities: 0x00000019 .... .... .... .... .... .... .... ...1 = Is a Router .... .... .... .... .... .... .... ..0. = Not a Transparent Bridge .... .... .... .... .... .... .... .0.. = Not a Source Route Bridge .... .... .... .... .... .... .... 1... = Is a Switch .... .... .... .... .... .... ...1 .... = Is a Host .... .... .... .... .... .... ..0. .... = Not IGMP capable .... .... .... .... .... .... .0.. .... = Not a Repeater Software Version Type: Software version (0x0005) Length: 23 Software Version: Chassis description Platform: Linux Type: Platform (0x0006) Length: 9 Platform: Linux */ char pkt1[] = { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x5e, 0x10, 0x8e, 0xe7, 0x84, 0xad, 0x00, 0x78, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x02, 0xb4, 0xc8, 0x67, 0x00, 0x01, 0x00, 0x12, 0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x20, 0x63, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x00, 0x02, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xac, 0x11, 0x8e, 0x24, 0x01, 0x01, 0xcc, 0x00, 0x04, 0xac, 0x11, 0x8e, 0x26, 0x00, 0x03, 0x00, 0x18, 0x47, 0x69, 0x67, 0x61, 0x62, 0x69, 0x74, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x35, 0x2f, 0x38, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x19, 0x00, 0x05, 0x00, 0x17, 0x43, 0x68, 0x61, 0x73, 0x73, 0x69, 0x73, 0x20, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x06, 0x00, 0x09, 0x4c, 0x69, 0x6e, 0x75, 0x78 }; struct packet *pkt; in_addr_t addr1; in_addr_t addr2; struct lldpd_mgmt *mgmt1; struct lldpd_mgmt *mgmt2; struct lldpd cfg = { .g_config = { .c_ttl = 180, .c_platform = "Linux" } }; /* Populate port and chassis */ hardware.h_lport.p_id_subtype = LLDP_PORTID_SUBTYPE_LLADDR; hardware.h_lport.p_id = macaddress; hardware.h_lport.p_id_len = ETHER_ADDR_LEN; hardware.h_lport.p_descr = "Gigabit Ethernet 5/8"; chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; chassis.c_id = macaddress; chassis.c_id_len = ETHER_ADDR_LEN; chassis.c_name = "Second chassis"; chassis.c_descr = "Chassis description"; chassis.c_cap_available = chassis.c_cap_enabled = LLDP_CAP_ROUTER | LLDP_CAP_BRIDGE; TAILQ_INIT(&chassis.c_mgmt); addr1 = inet_addr("172.17.142.36"); addr2 = inet_addr("172.17.142.38"); mgmt1 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr1, sizeof(in_addr_t), 0); mgmt2 = lldpd_alloc_mgmt(LLDPD_AF_IPV4, &addr2, sizeof(in_addr_t), 0); if (mgmt1 == NULL || mgmt2 == NULL) ck_abort(); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt1, m_entries); TAILQ_INSERT_TAIL(&chassis.c_mgmt, mgmt2, m_entries); /* Build packet */ n = cdpv2_send(&cfg, &hardware); if (n != 0) { fail("unable to build packet"); return; } if (TAILQ_EMPTY(&pkts)) { fail("no packets sent"); return; } pkt = TAILQ_FIRST(&pkts); ck_assert_int_eq(pkt->size, sizeof(pkt1)); fail_unless(memcmp(pkt->data, pkt1, sizeof(pkt1)) == 0); fail_unless(TAILQ_NEXT(pkt, next) == NULL, "more than one packet sent"); }
static void close_restricted(int fd, void *user_data) { /* for test devices we don't expect this to be called */ ck_abort(); }