assert(available);
}
-int clear_callback(const dlogutil_entry_s *ent, void *var)
+int failing_callback(const dlogutil_entry_s *ent, void *var)
{
+ assert(false);
return 1;
}
void clear_main()
{
assert(dlogutil_buffer_clear(DLOGUTIL_BUF_MAIN) == 0);
- assert(dlogutil_get_logs_dump(DLOGUTIL_BUF_MAIN, DLOGUTIL_MAX_DUMP_SIZE, clear_callback, NULL, NULL, NULL) == 0);
+ assert(dlogutil_get_logs_dump(DLOGUTIL_BUF_MAIN, DLOGUTIL_MAX_DUMP_SIZE, failing_callback, NULL, NULL, NULL) == 0);
+}
+
+void negative_main()
+{
+ void *bad_ptr = (void *)0xFA1l;
+
+ // NULL callback
+ assert(dlogutil_get_logs_continuous(DLOGUTIL_BUF_KMSG, NULL, NULL, NULL, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_get_logs_dump(DLOGUTIL_BUF_KMSG, DLOGUTIL_MAX_DUMP_SIZE, NULL, NULL, NULL, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+
+ // Invalid buffer combination
+ assert(dlogutil_get_logs_continuous(0, failing_callback, NULL, NULL, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_get_logs_dump(0, DLOGUTIL_MAX_DUMP_SIZE, failing_callback, NULL, NULL, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_get_logs_continuous(DLOGUTIL_BUF_MAIN | 1 << 16, failing_callback, NULL, NULL, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_get_logs_dump(DLOGUTIL_BUF_MAIN | 1 << 16, DLOGUTIL_MAX_DUMP_SIZE, failing_callback, NULL, NULL, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_get_logs_continuous(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, failing_callback, NULL, NULL, NULL) == TIZEN_ERROR_NOT_SUPPORTED);
+ assert(dlogutil_get_logs_dump(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, DLOGUTIL_MAX_DUMP_SIZE, failing_callback, NULL, NULL, NULL) == TIZEN_ERROR_NOT_SUPPORTED);
+
+ // Invalid single buffer
+ assert(dlogutil_buffer_clear(0) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_name(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_size(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_default_ts_type(0, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_check_ts_type_available(0, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_clear(1 << 16) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_name(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_size(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_default_ts_type(1 << 16, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_check_ts_type_available(1 << 16, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_clear(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_size(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_default_ts_type(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_check_ts_type_available(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+
+ // Retrieval of data from NULL
+ assert(dlogutil_entry_get_tid(NULL, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_pid(NULL, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_priority(NULL, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_timestamp(NULL, DLOGUTIL_SORT_RECV_MONO, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_tag(NULL, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_message(NULL, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+
+ // Retrieval of data into NULL
+ assert(dlogutil_entry_get_tid(bad_ptr, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_pid(bad_ptr, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_priority(bad_ptr, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_timestamp(bad_ptr, DLOGUTIL_SORT_RECV_MONO, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_tag(bad_ptr, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_entry_get_message(bad_ptr, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_size(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_get_default_ts_type(DLOGUTIL_BUF_MAIN, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_buffer_check_ts_type_available(DLOGUTIL_BUF_MAIN, DLOGUTIL_SORT_RECV_MONO, NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+
+ // Wrong timestamp
+ assert(dlogutil_entry_get_timestamp(bad_ptr, 1337, bad_ptr) == TIZEN_ERROR_INVALID_PARAMETER);
+
+ // NULL options
+ assert(dlogutil_filter_options_set_tid(NULL, 0) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_filter_options_set_pid(NULL, 0) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_filter_options_set_filterspec(NULL, "TIZEN") == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_sorting_options_disable_sorting(NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_sorting_options_enable_sorting(NULL) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_sorting_options_enable_sorting_with_size(NULL, 7) == TIZEN_ERROR_INVALID_PARAMETER);
+ assert(dlogutil_sorting_options_set_sort_by(NULL, DLOGUTIL_SORT_RECV_MONO) == TIZEN_ERROR_INVALID_PARAMETER);
+
+ // Destroying a NULL - no error, but doesn't crash either
+ dlogutil_filter_options_destroy(NULL);
+ dlogutil_sorting_options_destroy(NULL);
}
enum test_mode {
MODE_SORTING,
MODE_TRAITS,
MODE_CLEAR,
+ MODE_NEGATIVE,
MODE_INVALID,
};
[MODE_SORTING] = "sorting",
[MODE_TRAITS] = "traits",
[MODE_CLEAR] = "clear",
+ [MODE_NEGATIVE] = "negative",
};
const char *mode_desc[] = {
[MODE_SORTING] = "test timestamp sorting -- in this case, the PID is ignored",
[MODE_TRAITS] = "test buffer traits functionality -- in this case, the PID is ignored",
[MODE_CLEAR] = "test clearing functionality -- in this case, the PID is ignored",
+ [MODE_NEGATIVE] = "test whether libdlogutil errors out correctly",
};
void usage(const char *name)
} else if (t == MODE_CLEAR) {
clear_main();
return EXIT_SUCCESS;
+ } else if (t == MODE_NEGATIVE) {
+ negative_main();
+ return EXIT_SUCCESS;
}
struct test_data data = { .correct_tid_pid = atoi(argv[2]), .sleep = t == MODE_TIMER };