Exemplo n.º 1
0
Arquivo: main.c Projeto: wuwx/simba
int test_log_mask(struct harness_t *harness_p)
{
    struct log_object_t foo;

    /* Initialize the log objects. */
    BTASSERT(log_object_init(&foo,
                             "foo",
                             LOG_UPTO(INFO)) == 0);
    BTASSERT(log_object_get_log_mask(&foo) == 0x0f);

    /* Log all. */
    BTASSERT(log_object_set_log_mask(&foo, LOG_ALL) == 0);
    BTASSERT(log_object_get_log_mask(&foo) == 0x1f);

    /* Log none. */
    BTASSERT(log_object_set_log_mask(&foo, LOG_NONE) == 0);
    BTASSERT(log_object_get_log_mask(&foo) == 0x00);

    /* Log error. */
    BTASSERT(log_object_set_log_mask(&foo, LOG_MASK(ERROR)) == 0);
    BTASSERT(log_object_get_log_mask(&foo) == 0x02);

    /* Invalid levels are discarded. */
    BTASSERT(log_object_set_log_mask(&foo, 0xf0) == 0);
    BTASSERT(log_object_get_log_mask(&foo) == 0x10);

    /* Is enabled for. */
    BTASSERT(log_object_set_log_mask(&foo, LOG_MASK(ERROR)) == 0);
    BTASSERT(log_object_is_enabled_for(&foo, LOG_INFO) == 0);
    BTASSERT(log_object_is_enabled_for(&foo, LOG_ERROR) == 1);
    thrd_set_log_mask(thrd_self(), 0x00);
    BTASSERT(log_object_is_enabled_for(NULL, LOG_ERROR) == 0);

    return (0);
}
Exemplo n.º 2
0
static mp_obj_t module_thrd_set_log_mask(mp_obj_t thrd_in, mp_obj_t mask_in)
{
    thrd_set_log_mask((struct thrd_t *)(uintptr_t)mp_obj_get_int(thrd_in),
                      mp_obj_get_int(mask_in));

    return (mp_const_none);
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: wuwx/simba
int test_log_mask(struct harness_t *harness_p)
{
    char command[64];

    BTASSERT(thrd_get_log_mask() == 0x0f);
    BTASSERT(thrd_set_log_mask(thrd_self(), 0x00) == 0x0f);
    BTASSERT(thrd_get_log_mask() == 0x00);

    strcpy(command, "/kernel/thrd/set_log_mask main 0xff");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == 0);
    BTASSERT(thrd_get_log_mask() == 0xff);

    /* Invalid arguments. */
    strcpy(command, "/kernel/thrd/set_log_mask");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);
    BTASSERT(thrd_get_log_mask() == 0xff);

    strcpy(command, "/kernel/thrd/set_log_mask foo bar");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -ESRCH);
    BTASSERT(thrd_get_log_mask() == 0xff);

    strcpy(command, "/kernel/thrd/set_log_mask main foo");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);
    BTASSERT(thrd_get_log_mask() == 0xff);

    return (0);
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: wuwx/simba
static int test_init(struct harness_t *harness_p)
{
    struct thrd_t *thrd_p;
    int port = REMOTE_HOST_PORT;
    char remote_host_ip[] = STRINGIFY(REMOTE_HOST_IP);
    struct inet_addr_t remote_host_address;

    self_p = thrd_self();

    std_printf(FSTR("Connecting to '%s:%d'.\r\n"), remote_host_ip, port);

    BTASSERT(inet_aton(remote_host_ip, &remote_host_address.ip) == 0);
    remote_host_address.port = port;

    BTASSERT(socket_open_tcp(&server_sock) == 0);
    BTASSERT(socket_connect(&server_sock, &remote_host_address) == 0);

    BTASSERT(mqtt_client_init(&client,
                              "mqtt_client",
                              NULL,
                              &server_sock,
                              &server_sock,
                              on_publish,
                              NULL) == 0);

    thrd_p = thrd_spawn(mqtt_client_main,
                        &client,
                        0,
                        stack,
                        sizeof(stack));

    thrd_set_log_mask(thrd_p, LOG_UPTO(DEBUG));

    return (0);
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: wuwx/simba
static int test_start(struct harness_t *harness_p)
{
    struct inet_addr_t addr;

    socket_stub_init();

    inet_aton("127.0.0.1", &addr.ip);
    addr.port = 69;

    BTASSERT(tftp_server_init(&server,
                              &addr,
                              50,
                              "tftp_server",
                              NULL,
                              listener_stack,
                              sizeof(listener_stack)) == 0);
    BTASSERT(tftp_server_start(&server) == 0);
    thrd_set_log_mask(server.thrd_p, LOG_UPTO(DEBUG));

    return (0);
}