Ejemplo n.º 1
0
int
main(void)
{
    SXE_THREAD thread;
    SXE_RETURN result;
    unsigned   i;

    plan_tests(6);
    sxe_log_hook_line_out(test_log_line);
    test_log_level = sxe_log_set_level(SXE_LOG_LEVEL_LIBRARY_TRACE);    /* Required to do indentation test */
    sxe_spinlock_construct(&ping);
    sxe_spinlock_construct(&pong);
    is(sxe_spinlock_take(&ping), SXE_SPINLOCK_STATUS_TAKEN, "Ping lock taken by main");

    is((result = sxe_thread_create(&thread, test_thread_main, &ping, SXE_THREAD_OPTION_DEFAULTS)), SXE_RETURN_OK,
                                                            "Created SXE thread");
    sxe_spinlock_give(&ping);    /* Allow thread to proceed */

    /* Wait for thread_indent to be set.
     */
    for (i = 0; thread_indent == 0 && i < TEST_YIELD_MAX; i++) {
        SXE_YIELD();
    }

    ok(i < TEST_YIELD_MAX,                                  "Thread log indent set to %u after %u yeilds", thread_indent, i);
    SXEL10("main: about to confirm the pong from the thread");
    is(sxe_spinlock_take(&pong), SXE_SPINLOCK_STATUS_TAKEN, "Pong lock taken by main");
    ok(main_indent > 0,                                     "Main log indent set to %u", main_indent);
    ok(thread_indent > main_indent,                         "Thread indent is greater than main indent");
    return exit_status();
}
Ejemplo n.º 2
0
int
main(int argc, char ** argv)
{
    const char * line;
    unsigned     i;

    if (argc > 1) {
        test_program_arg = argv[1];
        sxe_log_hook_line_out(test_log_line_out_to_stdout);
        SXEA10(sxe_log_hook_line_out(test_log_line_out_to_stdout) == test_log_line_out_to_stdout,
               "sxe_log_hook_line_out failed to hook test_log_line_out_to_stdout");

        if (strcmp(argv[1], "1") == 0) {
            if (getenv("SXE_LOG_LEVEL") != NULL) {
                SXED80("should not see this (level too high)", strlen("should not see this (level too high)"));    /* Cover early out in dump */
            }

            SXEL40("BOO");
        }
        else if (strcmp(argv[1], "2") == 0) {
#ifndef LOCAL_SXE_DEBUG
            sxe_log_set_indent_maximum(~0U);
#endif
            sxe_log_set_level(SXE_LOG_LEVEL_WARNING);
            SXEE50("level_five()");
            test_level_six(SXE_LOG_LEVEL_LIBRARY_DUMP);
            SXER50("return // five");
            SXEE50("level_five()");
            test_level_six(SXE_LOG_LEVEL_WARNING);
            SXER50("return // five");
            SXEL20("that's all, folks");
        }

        exit(0);
    }

    test_program_name = argv[0];
    plan_tests(3 * TEST_LINES_EXPECTED + 3);

    /* Tests for different log level settings */

    tap_test_case_name("Level settings");
    ok((line = test_log_first("1")) != NULL,                        "Test log at default level wrote a line");
    diag("line = %s", line);

    SXEA12(putenv((char *)(intptr_t)"SXE_LOG_LEVEL=2") >= 0,        "%s: Failed to putenv: %s", test_program_name, strerror(errno));
    ok(test_log_first("1") == NULL,                                 "Test log with SXE_LOG_LEVEL=2 failed to write a line");

    /* TODO: Replace putenvs with calls to the TBD function that allows setting fine grained levels programmatically. */

    SXEA12(putenv((char *)(intptr_t)"SXE_LOG_LEVEL_LIBSXE=5") >= 0, "%s: Failed to putenv: %s", test_program_name, strerror(errno));
    ok((line = test_log_first("1")) != NULL,                        "Test log with SXE_LOG_LEVEL_LIBSXE=5 wrote a line");
    diag("line = %s", line);
    SXEA12(putenv((char *)(intptr_t)"SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LOG=2") >= 0, "%s: Failed to setenv: %s", test_program_name, strerror(errno));
    ok(test_log_first("1") == NULL,                                 "Test log with SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LOG=2 failed to write a line");
    SXEA12(putenv((char *)(intptr_t)"SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LOG_TEST_TEST_SXE_LOG_LEVELS=7") >= 0, "%s: Failed to putenv: %s", test_program_name, strerror(errno));
    ok((line = test_log_first("1")) != NULL,                        "Test log with SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LOG_TEST_TEST_SXE_LOG_LEVELS=7 wrote a line");
    diag("line = %s", line);

    /* Remove the more specific environment variables
     */
    SXEA12(unsetenv("SXE_LOG_LEVEL_LIBSXE") == 0,                                      "%s: unsetenv failed: %s", test_program_name, strerror(errno));
    SXEA12(unsetenv("SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LOG") == 0,                          "%s: unsetenv failed: %s", test_program_name, strerror(errno));
    SXEA12(unsetenv("SXE_LOG_LEVEL_LIBSXE_LIB_SXE_LOG_TEST_TEST_SXE_LOG_LEVELS") == 0, "%s: unsetenv failed: %s", test_program_name, strerror(errno));

    /* Tests for indentation interacting with log level */

    tap_test_case_name("Indentation");
    line = test_log_first("2");

    for (i = 0; i < TEST_LINES_EXPECTED; i++) {
        ok(line != NULL,                                            "Got line %u", 2 * i + 1);
        ok(strstr(line, test_expected[i]) != NULL,                  "Found '%s' in '%.*s'", test_expected[i], (int)strlen(line) - 1, line);

        if (i > 2) {
            ok(test_log_next() != NULL,                             "Got line %u", 2 * i + 2);
        }

        line = test_log_next();
    }

    ok(line == NULL,                                                "Got EOF");
    return exit_status();
}
Ejemplo n.º 3
0
int
main(void) {
    struct object   self;
    struct object * this = &self;

    plan_tests(47);

    /* Test sxe_return_to_string()
     */
    is_eq(sxe_return_to_string(SXE_RETURN_OK),             "OK"            , "sxe_return_to_string(SXE_RETURN_OK) eq \"OK\"");
    is_eq(sxe_return_to_string(SXE_RETURN_ERROR_INTERNAL), "ERROR_INTERNAL", "sxe_return_to_string(SXE_RETURN_ERROR_INTERNAL) eq \"ERROR_INTERNAL\"");
    is(   sxe_return_to_string(~0U),                        NULL,            "sxe_return_to_string(~0U) == NULL");
    TEST_CASE_RETURN_TO_STRING(EXPIRED_VALUE);
    TEST_CASE_RETURN_TO_STRING(NO_UNUSED_ELEMENTS);
    TEST_CASE_RETURN_TO_STRING(IN_PROGRESS);
    TEST_CASE_RETURN_TO_STRING(UNCATEGORIZED);
    TEST_CASE_RETURN_TO_STRING(END_OF_FILE);
    TEST_CASE_RETURN_TO_STRING(WARN_ALREADY_INITIALIZED);
    TEST_CASE_RETURN_TO_STRING(WARN_WOULD_BLOCK);
    TEST_CASE_RETURN_TO_STRING(WARN_ALREADY_CLOSED);
    TEST_CASE_RETURN_TO_STRING(ERROR_NOT_INITIALIZED);
    TEST_CASE_RETURN_TO_STRING(ERROR_ALLOC);
    TEST_CASE_RETURN_TO_STRING(ERROR_NO_CONNECTION);
    TEST_CASE_RETURN_TO_STRING(ERROR_ALREADY_CONNECTED);
    TEST_CASE_RETURN_TO_STRING(ERROR_INVALID_URI);
    TEST_CASE_RETURN_TO_STRING(ERROR_BAD_MESSAGE);
    TEST_CASE_RETURN_TO_STRING(ERROR_ADDRESS_IN_USE);
    TEST_CASE_RETURN_TO_STRING(ERROR_INTERRUPTED);
    TEST_CASE_RETURN_TO_STRING(ERROR_COMMAND_NOT_RUN);
    TEST_CASE_RETURN_TO_STRING(ERROR_LOCK_NOT_TAKEN);
    TEST_CASE_RETURN_TO_STRING(ERROR_INCORRECT_STATE);
    TEST_CASE_RETURN_TO_STRING(ERROR_TIMED_OUT);
    TEST_CASE_RETURN_TO_STRING(ERROR_WRITE_FAILED);
    TEST_CASE_RETURN_TO_STRING(INVALID_VALUE);           /* Just for coverage */

    ok(signal(SIGABRT, test_abort_handler) != SIG_ERR, "Caught abort signal");
    sxe_log_hook_line_out(NULL); /* for coverage */
    sxe_log_hook_line_out(log_line);
    PUTENV("SXE_LOG_LEVEL=6");   /* Trigger processing of the level in the first call to the log */
    SXEE60(entering);
    PUTENV("SXE_LOG_LEVEL=1");   /* This should be ignored. If it is not, the tests will fail    */
    this->id = 99;
    SXEL60I(logging);
    SXEA60(1, "Asserting true");
    SXED60(dumpdata, 4);
    SXER60(exiting);
    SXEL60(verylong);
    SXEE61("really long entry message: %s", verylong);
    SXEL60(escape);
    SXEL60(hextrunc);
    SXED60(dumpdata, 0);    /* Edge case */
    SXEA80(1, "We should not get this, because level 8 is too low!");

    is(sxe_log_decrease_level(SXE_LOG_LEVEL_ERROR),       SXE_LOG_LEVEL_TRACE,       "Level decreased to ERROR (2) from TRACE (6)");
    is(sxe_log_set_level(     SXE_LOG_LEVEL_INFORMATION), SXE_LOG_LEVEL_ERROR,       "Level set to INFO, was ERROR");
    is(sxe_log_decrease_level(SXE_LOG_LEVEL_TRACE),       SXE_LOG_LEVEL_INFORMATION, "Level was INFO, TRACE is not a decrease");

#if defined(_WIN32) && defined(LOCAL_SXE_DEBUG)
    skip(3, "Can't test aborts in a Windows debug build, due to pop up Window stopping the build");
#else
    SXEA60(this != &self, "This is not self");  /* Abort - must be the last thing we do*/
    fail("Did not catch an abort signal");
#endif
    }    /* Oog! Close the brace opened in the SXEE61 macro above */