Ejemplo n.º 1
0
void
cleanup(int sig)
{
#ifdef _CRAY
    static int incleanup = 0;
    int t;
    int child_status; /* status of child process as returned by waitpid */
    int flags = WNOHANG|WUNTRACED;

    /*
     * 1: Pick up the zombie, if we are being called
     *    as the signal handler.
     * 2: If we are a nested cleanup(), return.
     * 3: Try to clean up TMPDIR.
     * 4: Fill in utmp with shutdown of process.
     * 5: Close down the network and pty connections.
     * 6: Finish up the TMPDIR cleanup, if needed.
     */
    if (sig == SIGCHLD) {
	while (waitpid(-1, &child_status, flags) > 0)
	    ;	/* VOID */
	/* Check if the child process was stopped
	 * rather than exited.  We want cleanup only if
	 * the child has died.
	 */
	if (WIFSTOPPED(child_status)) {
	    return;
	}
    }
    t = sigblock(sigmask(SIGCHLD));
    if (incleanup) {
	sigsetmask(t);
	return;
    }
    incleanup = 1;
    sigsetmask(t);

    t = cleantmp(&wtmp);
    setutent();	/* just to make sure */
#endif /* CRAY */
    rmut(line);
    close(ourpty);
    shutdown(net, 2);
#ifdef _CRAY
    if (t == 0)
	cleantmp(&wtmp);
#endif /* CRAY */
    exit(1);
}
Ejemplo n.º 2
0
int test_sky_table_open() {
    struct tagbstring lock_file_path = bsStatic("tmp/.skylock");
    struct tagbstring data_file_path = bsStatic("tmp/0/data");
    struct tagbstring header_file_path = bsStatic("tmp/0/header");
    cleantmp();
    
    int rc;
    sky_table *table = sky_table_create();
    table->path = bfromcstr("tmp");
    
    // Open table.
    rc = sky_table_open(table);
    mu_assert_int_equals(rc, 0);
    mu_assert(sky_file_exists(&lock_file_path), "");
    mu_assert(sky_file_exists(&data_file_path), "");
    mu_assert(sky_file_exists(&header_file_path), "");
    
    // Close table.
    rc = sky_table_close(table);
    mu_assert_int_equals(rc, 0);
    mu_assert(!sky_file_exists(&lock_file_path), "");
    mu_assert(sky_file_exists(&data_file_path), "");
    mu_assert(sky_file_exists(&header_file_path), "");

    sky_table_free(table);
    return 0;
}
Ejemplo n.º 3
0
int test_sky_data_file_load_empty() {
    cleantmp();
    
    int rc;
    sky_data_file *data_file = sky_data_file_create();
    data_file->block_size = 128;
    data_file->path = bfromcstr("tmp/data");
    data_file->header_path = bfromcstr("tmp/header");
    
    rc = sky_data_file_load(data_file);
    mu_assert_int_equals(rc, 0);

    mu_assert_bool(data_file->data != NULL);
    mu_assert_bool(data_file->data_fd != 0);
    mu_assert_long_equals(data_file->data_length, 128L);
    mu_assert_bool(data_file->blocks != NULL);
    mu_assert_int_equals(data_file->block_count, 1);
    mu_assert_file("tmp/data", "tests/fixtures/data_files/0/data");
    mu_assert_file("tmp/header", "tests/fixtures/data_files/0/header");

    rc = sky_data_file_unload(data_file);
    mu_assert_int_equals(rc, 0);
    
    mu_assert_bool(data_file->data == NULL);
    mu_assert_bool(data_file->data_fd == 0);
    mu_assert_long_equals(data_file->data_length, 0L);
    mu_assert_bool(data_file->blocks == NULL);
    mu_assert_int_equals(data_file->block_count, 0);

    sky_data_file_free(data_file);
    return 0;
}
Ejemplo n.º 4
0
int test_sky_add_event_message_pack() {
    cleantmp();
    sky_add_event_message *message = create_message_with_data();
    FILE *file = fopen("tmp/message", "w");
    mu_assert_bool(sky_add_event_message_pack(message, file) == 0);
    fclose(file);
    mu_assert_file("tmp/message", "tests/fixtures/add_event_message/0/message");
    sky_add_event_message_free(message);
    return 0;
}
Ejemplo n.º 5
0
int test_sky_get_actions_message_pack() {
    cleantmp();
    sky_get_actions_message *message = sky_get_actions_message_create();
    
    FILE *file = fopen("tmp/message", "w");
    mu_assert_bool(sky_get_actions_message_pack(message, file) == 0);
    fclose(file);
    mu_assert_file("tmp/message", "tests/fixtures/get_actions_message/0/message");
    sky_get_actions_message_free(message);
    return 0;
}
Ejemplo n.º 6
0
int test_sky_peach_message_pack() {
    cleantmp();
    sky_peach_message *message = sky_peach_message_create();
    message->query = bfromcstr("class Foo{ public Int x; }");
    
    FILE *file = fopen("tmp/message", "w");
    mu_assert_bool(sky_peach_message_pack(message, file) == 0);
    fclose(file);
    mu_assert_file("tmp/message", "tests/fixtures/peach_message/0/message");
    sky_peach_message_free(message);
    return 0;
}
Ejemplo n.º 7
0
int test_sky_message_header_pack() {
    cleantmp();
    sky_message_header *header = sky_message_header_create();
    header->version = 1;
    header->name = bfromcstr("eadd");
    header->table_name = bfromcstr("bar");
    
    FILE *file = fopen("tmp/message", "w");
    mu_assert_bool(sky_message_header_pack(header, file) == 0);
    fclose(file);
    mu_assert_file("tmp/message", "tests/fixtures/message_header/0/message");
    sky_message_header_free(header);
    return 0;
}
Ejemplo n.º 8
0
int test_sky_create_table_message_pack() {
    cleantmp();
    sky_create_table_message *message = sky_create_table_message_create();
    message->data_path = bfromcstr("/tmp/data");
    message->table = sky_table_create();
    message->table->path = bfromcstr("/tmp/data/foo");
    message->table->default_tablet_count = 10;
    
    FILE *file = fopen("tmp/message", "w");
    mu_assert_bool(sky_create_table_message_pack(message, file) == 0);
    fclose(file);
    mu_assert_file("tmp/message", "tests/fixtures/create_table_message/0/message");
    sky_table_free(message->table);
    sky_create_table_message_free(message);
    return 0;
}
Ejemplo n.º 9
0
int test_sky_importer_import() {
    cleantmp();
    sky_importer *importer = sky_importer_create();
    importer->path = bfromcstr("tmp");
    
    FILE *file = fopen("tests/fixtures/importer/0/data.json", "r");
    int rc = sky_importer_import(importer, file);
    mu_assert_int_equals(rc, 0);
    fclose(file);
    
    // Validate.
    mu_assert_bool(importer->table != NULL);
    mu_assert_int_equals(importer->table->default_block_size, 128);
    mu_assert_file("tmp/actions", "tests/fixtures/importer/0/table/actions");
    mu_assert_file("tmp/properties", "tests/fixtures/importer/0/table/properties");
    mu_assert_file("tmp/0/data", "tests/fixtures/importer/0/table/0/data");
    mu_assert_file("tmp/0/header", "tests/fixtures/importer/0/table/0/header");

    sky_importer_free(importer);
    return 0;
}
Ejemplo n.º 10
0
int test_sky_create_table_message_process() {
    cleantmp();
    sky_server *server = sky_server_create(NULL);
    server->path = bfromcstr("tmp");
    sky_message_header *header = sky_message_header_create();

    FILE *input = fopen("tests/fixtures/create_table_message/1/input", "r");
    FILE *output = fopen("tmp/output", "w");
    int rc = sky_create_table_message_process(server, header, NULL, input, output);
    mu_assert_int_equals(rc, 0);
    
    struct tagbstring foo_db_path = bsStatic("tmp/foo");
    struct tagbstring foo_db_0_path = bsStatic("tmp/foo/0");
    struct tagbstring foo_db_9_path = bsStatic("tmp/foo/9");
    mu_assert_bool(sky_file_exists(&foo_db_path));
    mu_assert_bool(sky_file_exists(&foo_db_0_path));
    mu_assert_bool(sky_file_exists(&foo_db_9_path));
    mu_assert_file("tmp/output", "tests/fixtures/create_table_message/1/output");

    sky_message_header_free(header);
    sky_server_free(server);
    return 0;
}