Exemplo n.º 1
0
Arquivo: sosh.c Projeto: gapry/AOS
static int kill(int argc, char **argv) {
    pid_t pid;

    if (argc != 2) {
        printf("Usage: %s <pid>\n", argv[0]);
        return 1;
    }

    pid = (pid_t)atoi(argv[1]);
    if (sos_process_delete(pid)) {
        printf("invalid process\n");
        return 1;
    }

    return 0;
}
Exemplo n.º 2
0
static int kill(int argc, char **argv) {
    int err;

    if (argc != 2) {
        printf("Usage: kill pid\n");
        return 1;
    }

    pid_t pid = atoi(argv[1]);
    err = sos_process_delete(pid);
    if (err != 0) {
        printf("Failed!\n");
    } else {
        printf("Killed pid=%d\n", pid);
    }

    return 0;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
static int shexit(int argc, char **argv) {
    sos_process_delete(0);
    return 0;
}
Exemplo n.º 5
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);
}