コード例 #1
0
ファイル: main.c プロジェクト: 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);
}
コード例 #2
0
ファイル: main.c プロジェクト: eerimoq/simba
int test_fs(struct harness_t *harness_p)
{
    char command[64];
    struct command_t *command_p;
    struct command_t commands[] = {
        { "/debug/log/list", 0 },
        { "/debug/log/print foo", 0 },
        { "/debug/log/set_log_mask log 0xff", 0 },
        
        { "/debug/log/list d", -EINVAL },
        { "/debug/log/print d d", -EINVAL },
        { "/debug/log/set_log_mask invalid_object 0xff", -EINVAL },
        { "/debug/log/set_log_mask missing_mask", -EINVAL },
        { "/debug/log/set_log_mask bad_mask ds", -EINVAL },
        { NULL, 0 }
    };

    command_p = &commands[0];

    while (command_p->command_p != NULL) {
        strcpy(command, command_p->command_p);
        BTASSERT(fs_call(command,
                         NULL,
                         sys_get_stdout(),
                         NULL) == command_p->res);

        command_p++;
    }

    return (0);
}
コード例 #3
0
ファイル: main.c プロジェクト: eerimoq/simba
int test_get_temp(struct harness_t *harness_p)
{
    struct owi_driver_t owi;
    struct ds18b20_driver_t ds;
    struct owi_device_t devices[4];
    char buf[24];
    int number_of_sensors;

    BTASSERT(owi_init(&owi, &pin_d7_dev, devices, membersof(devices)) == 0);
    BTASSERT(ds18b20_init(&ds, &owi) == 0);

    time_busy_wait_us(50000);

    number_of_sensors = owi_search(&owi);

    std_printf(FSTR("number_of_sensors = %d\r\n"), number_of_sensors);

    BTASSERT(number_of_sensors == 2);

    strcpy(buf, "drivers/ds18b20/list");
    BTASSERT(fs_call(buf, NULL, sys_get_stdout(), NULL) == 0);

    time_busy_wait_us(50000);

    return (0);
}
コード例 #4
0
ファイル: module_os.c プロジェクト: eerimoq/pumbaa
/**
 * def system(command)
 */
static mp_obj_t os_system(mp_obj_t command_in)
{
    int res;
    char command[128];
    struct vstr_chan_t chout;

    strncpy(command, mp_obj_str_get_str(command_in), membersof(command));
    command[membersof(command) - 1] = '\0';

    vstr_chan_init(&chout);

    res = fs_call(command, sys_get_stdin(), &chout, NULL);

    if (res == -ENOENT) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "Command not found: '%s'",
                                                mp_obj_str_get_str(command_in)));
    } else if (res != 0) {
        nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
                                                "Command failed with %d",
                                                res));
    }

    return (mp_obj_new_str_from_vstr(&mp_type_str,
                                     vstr_chan_get_vstr(&chout)));
}
コード例 #5
0
ファイル: main.c プロジェクト: wuwx/simba
static int test_cmd_ping_bad_input(struct harness_t *harness_p)
{
    char buf[128];
    
    /* Too few arguemnts. */
    strcpy(buf, "inet/ping/ping\r\n");
    BTASSERT(fs_call(buf, NULL, &qout, NULL) == -1);
    BTASSERT(harness_expect(&qout,
                            "Usage: ping <remote host>\r\n",
                            NULL) == 27);

    /* Bad ip address. */
    strcpy(buf, "inet/ping/ping a.b.c.d\r\n");
    BTASSERT(fs_call(buf, NULL, &qout, NULL) == -1);
    BTASSERT(harness_expect(&qout,
                            "Bad ip address 'a.b.c.d'.\r\n",
                            NULL) == 27);
        
    return (0);
}
コード例 #6
0
ファイル: main.c プロジェクト: wuwx/simba
int test_monitor_thread(struct harness_t *harness_p)
{
    char command[64];

    /* Missing print value. */
    strcpy(command, "/kernel/thrd/monitor/set_print");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);

    /* Bad print integer value. */
    strcpy(command, "/kernel/thrd/monitor/set_print 2");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);

    /* Bad print value. */
    strcpy(command, "/kernel/thrd/monitor/set_print foo");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == -EINVAL);

    /* Start printing. */
    strcpy(command, "/kernel/thrd/monitor/set_print 1");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == 0);

    /* Wait a while for monitor thread output.*/
    thrd_sleep_ms(30);

    strcpy(command, "/kernel/thrd/monitor/set_period_ms 10");
    BTASSERT(fs_call(command, NULL, chan_null(), NULL) == 0);

    /* Wait a while for monitor thread output.*/
    thrd_sleep_ms(30);

    /* Stop printing. */
    strcpy(command, "/kernel/thrd/monitor/set_print 0");
    BTASSERT(fs_call(command, NULL, sys_get_stdout(), NULL) == 0);

    /* Missing period. */
    strcpy(command, "/kernel/thrd/monitor/set_period_ms");
    BTASSERT(fs_call(command, NULL, chan_null(), NULL) == -EINVAL);

    /* Bad period. */
    strcpy(command, "/kernel/thrd/monitor/set_period_ms bar");
    BTASSERT(fs_call(command, NULL, chan_null(), NULL) == -EINVAL);

    return (0);
}
コード例 #7
0
ファイル: main.c プロジェクト: wuwx/simba
static int test_cmd_ping_bad_reply(struct harness_t *harness_p)
{
    uint8_t reply[28];
    char buf[128];

    /* Prepare the socket stub with a bad reply packet. The first 20
       bytes in the reply are the IP header. */
    reply[20] = 0;
    reply[21] = 0;
    reply[22] = 0xff;
    reply[23] = 0xfe;
    reply[24] = 0;
    reply[25] = 2;
    reply[26] = 0;
    reply[27] = 2;
    socket_stub_input(reply, sizeof(reply));

    /* Perform the ping. */
    strcpy(buf, "inet/ping/ping 1.1.1.1\r\n");
    BTASSERT(fs_call(buf, NULL, &qout, NULL) == 0);
    BTASSERT(harness_expect(&qout, "Failed to ping '1.1.1.1'.\r\n", NULL) > 0);
        
    return (0);
}
コード例 #8
0
ファイル: main.c プロジェクト: wuwx/simba
static int test_cmd_ping(struct harness_t *harness_p)
{
    uint8_t request[8];
    uint8_t reply[28];
    char buf[128];

    /* Prepare the socket stub with the reply packet. The first 20
       bytes in the reply are the IP header. */
    reply[20] = 0;
    reply[21] = 0;
    reply[22] = 0xff;
    reply[23] = 0xfc;
    reply[24] = 0;
    reply[25] = 2;
    reply[26] = 0;
    reply[27] = 1;
    socket_stub_input(reply, sizeof(reply));

    /* Perform the ping. */
    strcpy(buf, "inet/ping/ping 1.1.1.1\r\n");
    BTASSERT(fs_call(buf, NULL, &qout, NULL) == 0);
    harness_expect(&qout, "Successfully pinged '1.1.1.1' in 0 ms.\r\n", NULL);
    
    /* Check the request send by the ping module. */
    socket_stub_output(request, sizeof(request));
    BTASSERT(request[0] == 8);
    BTASSERT(request[1] == 0);
    BTASSERT(request[2] == 0xf7);
    BTASSERT(request[3] == 0xfc);
    BTASSERT(request[4] == 0);
    BTASSERT(request[5] == 2);
    BTASSERT(request[6] == 0);
    BTASSERT(request[7] == 1);
        
    return (0);
}
コード例 #9
0
ファイル: main.c プロジェクト: wuwx/simba
int test_fs(struct harness_t *harness_p)
{
    char command[64];
    struct queue_t queue;
    uint8_t buf[256];
    struct command_t *command_p;
    struct command_t commands[] = {
        { "/debug/log/list",
          0,
          "OBJECT-NAME       MASK\r\n"
          "log               0x0f\r\n"
        },
        { "/debug/log/print foo", 0, NULL },
        { "/debug/log/set_log_mask log 0xff", 0, NULL },

        {
            "/debug/log/list d",
            -EINVAL,
            "Usage: list\r\n"
        },
        {
            "/debug/log/print d d",
            -EINVAL,
            "Usage: print <string>\r\n"
        },
        {
            "/debug/log/set_log_mask invalid_object 0xff",
            -EINVAL,
            "No log object with name 'invalid_object'.\r\n" },
        {
            "/debug/log/set_log_mask missing_mask",
            -EINVAL,
            "Usage: set_log_mask <object> <mask>\r\n"
        },
        {
            "/debug/log/set_log_mask bad_mask ds",
            -EINVAL,
            "Bad mask 'ds'.\r\n"
        },
        { NULL, 0, NULL }
    };

    BTASSERT(queue_init(&queue, &buf[0], sizeof(buf)) == 0);

    command_p = &commands[0];

    while (command_p->command_p != NULL) {
        strcpy(command, command_p->command_p);
        BTASSERT(fs_call(command,
                         NULL,
                         &queue,
                         NULL) == command_p->res);

        if (command_p->output_p != NULL) {
            BTASSERTI(harness_expect(&queue,
                                     command_p->output_p,
                                     NULL), ==, strlen(command_p->output_p));
        }

        command_p++;
    }