Esempio n. 1
0
static int exec(int argc, char **argv) {
    pid_t pid;
    int r;
    int bg = 0;

    if (argc < 2 || (argc > 2 && argv[2][0] != '&')) {
        printf("Usage: exec filename [&]\n");
        return 1;
    }

    if ((argc > 2) && (argv[2][0] == '&')) {
        bg = 1;
    }

    if (bg == 0) {
        r = close(in);
        assert(r == 0);
    }

    pid = sos_process_create(argv[1]);
    if (pid >= 0) {
        printf("Child pid=%d\n", pid);
        if (bg == 0) {
            sos_process_wait(pid);
        }
    } else {
        printf("Failed!\n");
    }
    if (bg == 0) {
        in = open("console", O_RDONLY);
        assert(in >= 0);
    }
    return 0;
}
Esempio n. 2
0
int main() {
    /* Implementation defined. Set this to your initial id. */
    if (sos_my_id() != 0) {
        printf("I am a child with pid: %d.\n", sos_my_id());
        /* Try to delete our parent. Once again this is implementation defined.*/
        assert(sos_process_delete(sos_my_id() - 1) == -1);
        assert(sos_process_wait(sos_my_id() - 1) == -1);
        printf("Child test exited successfully.\n");
        return 0;
    }

    printf("Running timer error tests.\n");
    timer_errors();
    printf("Timer error tests passed.\n");

    printf("Running file error tests.\n");
    file_errors();
    printf("File error tests passed.\n");

    printf("Running memory error tests.\n");
    printf("Warning: Here be implementation specific dragons.\n");
    memory_errors();
    printf("Memory error tests passed.\n");

    printf("Running process error tests.\n");
    process_errors();
    printf("Process error tests passed.\n");

    // TODO(karl): Write share vm tests.

    printf("Running crash tests. You need to manually comment out individual lines.\n");
    crash_errors();
    assert(!"Crash tests failed you should never get here!\n");

    return 0;
}
Esempio n. 3
0
void process_errors() {
    char path[2 * MAX_PATH_LENGTH];
    for (int i = 0; i < 2 * MAX_PATH_LENGTH; i++) {
        path[i] = 'a';
    }

    assert(sos_process_create(NULL) == -1);
    assert(sos_process_create((char *)1000) == -1);
    assert(sos_process_create((char *)~0) == -1);
    assert(sos_process_create("") == -1);
    assert(sos_process_create("non_existant_process") == -1);
    assert(sos_process_create(path) == -1);
    path[MAX_PATH_LENGTH] = '\0';
    assert(sos_process_create(path) == -1);

    assert(sos_process_delete(-1) == -1);
    assert(sos_process_delete(INT_MIN) == -1);
    assert(sos_process_delete(INT_MAX) == -1);
    assert(sos_process_delete(sos_my_id() + 1) == -1);

    sos_process_t process_buff[100];
    /* Not an error but a corner case. */
    assert(sos_process_status(process_buff, 0) == 0);
    assert(sos_process_status(process_buff, 100) == 1);
    assert(sos_process_status(NULL, 100) == 0);
    assert(sos_process_status((void *)1000, 100) == 0);
    assert(sos_process_status((void *)~0, 100) == 0);
    assert(sos_process_status(sbrk(0), 1) == 0);
    assert(sos_process_status((void *)"read only string", 1) == 0);

    assert(sos_process_wait(sos_my_id() + 1) == -1);
    assert(sos_process_wait(INT_MIN) == -1);
    assert(sos_process_wait(INT_MAX) == -1);
    /* Implementation defined this might be allowed behaviour. */
    assert(sos_process_wait(sos_my_id()) == -1);

    pid_t pid = sos_process_create("error_test");
    assert(pid != -1);
    assert(sos_process_wait(pid) == pid);
    assert(sos_process_wait(pid) == -1);

    pid = sos_process_create("error_test");
    assert(pid != -1);
    assert(sos_process_delete(pid) == 0);
    assert(sos_process_delete(pid) == -1);

    pid = sos_process_create("error_test");
    assert(pid != -1);
    assert(sos_process_delete(pid) == 0);
    assert(sos_process_wait(pid) == -1);

    pid = sos_process_create("error_test");
    assert(pid != -1);
    assert(sos_process_wait(pid) == pid);
    assert(sos_process_delete(pid) == -1);

    pid = sos_process_create("error_test");
    assert(pid != -1);
    sos_sys_usleep(10000);
    assert(sos_process_create("error_test") != pid);
    assert(sos_process_wait(pid) == pid);
}