예제 #1
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
static void
test_write_sizes(size_t max_size)
{
    size_t s;
    char *buf, *b2;
    size_t l;

    buf = malloc(max_size);
    if (!buf) {
        printf("no memory");
        exit(1);
    }
    for (s = 0; s < max_size; s++) {
        buf[s] = 0;
        if (!xs_write(xs_handle, "data/test/key1", buf))
            break;
        b2 = xs_read(xs_handle, "data/test/key1", &l);
        if (!b2) {
            fail_test(__LINE__, "failed to read in size %d", s);
        } else if (l != s) {
            fail_test(__LINE__, "read wrong size %d != %d", s, l);
        } else if (strcmp(b2, buf)) {
            fail_test(__LINE__, "read wrong data size %d %s ! = %s",
                      s, b2, buf);
        }
        if (b2)
            free(b2);
        buf[s] = 'X';
    }
    /* Experimentally, 2027 is the maximum key size we can write
       before we hit xenstore quota limits. */
    if (s < 2027)
        fail_test(__LINE__, "Could only write %d bytes to xenstore", s);
    free(buf);
}
예제 #2
0
void orbital_selector_test::test_1() {

    static const char *testname = "orbital_selector_test::test_1()";

    //
    // Test setting up a orbital_selector with no elements selected
    //

    size_t n = 10;

    orbital_selector s(n);

    if (s.n_indexes() != n) {
        fail_test(testname, __FILE__, __LINE__, "# indexes.");
    }
    if (s.n_selected() != 0) {
        fail_test(testname, __FILE__, __LINE__, "# selected.");
    }
    if (! s.none_selected()) {
        fail_test(testname, __FILE__, __LINE__, "None selected.");
    }
    std::vector<size_t> indexes = s.get_selected();
    if (indexes.size() != 0) {
        fail_test(testname, __FILE__, __LINE__, "# indexes.");
    }
}
예제 #3
0
/** \brief Test construction of an empty grid
 **/
void export_cube_base_test::test_1() {

    static const char *testname = "export_cube_base_test::test_1()";

    try {

    export_cube_test ex;
    mat dm1(ex.nao(), ex.nao(), fill::randu);
    mat dm2(ex.nao(), ex.nao(), fill::randu);
    mat orb1(ex.nao(), 4, fill::randu);
    mat orb2(ex.nao(), 5, fill::randu);
    std::vector<size_t> i1(4, 0), i2(5, 0);
    for (size_t i = 0; i < 4; i++) i1[i] = 2 * i;
    for (size_t i = 0; i < 5; i++) i2[i] = i;

    ex.perform("dm1", "First test density matrix", dm1);
    ex.perform("dm2", "Second test density matrix", dm2);
    ex.perform("orb1", "First test density matrix", i1, orb1);
    ex.perform("orb2", "Second test density matrix", i2, orb2);

    ex.do_export();

    } catch (libwfa_exception &e) {
        fail_test(testname, __FILE__, __LINE__, e.what());
    }
}
예제 #4
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
static DWORD WINAPI
thread_func(PVOID _ident)
{
    int ident;
    HANDLE h;
    int x;
    char path[4096], buf[2000];
    char *t;
    size_t l;

    ident = (int)(ULONG_PTR)_ident;
    h = xs_domain_open();
    if (!h) win_err(1, "thread %d can't start", ident);

    sprintf(path, "data/test/thread%d", ident);
    for (x = 0; x < 5000; x++) {
        if ( (ident + x) % 256 == 0)
            memset(buf, 1, sizeof(buf));
        else
            memset(buf, ident + x, sizeof(buf));
        buf[sizeof(buf)-1] = 0;
        if (!xs_write(h, path, buf))
            fail_test(__LINE__, "thread %d pass %d", ident, x);
        t = xs_read(h, path, &l);
        if (!t) {
            if (GetLastError() == ERROR_FILE_NOT_FOUND) {
                printf("ERROR_NOT_FOUND, did the VM get suspended?\n");
            } else {
                fail_test(__LINE__, "thread %d pass %d (%d)", ident, x,
                          GetLastError());
            }
        } else {
            if (l != sizeof(buf)-1)
                fail_test(__LINE__, "thread %d pass %d (%d, %d)", ident, x,
                          l, sizeof(buf)-1);
            if (strcmp(buf, t))
                fail_test(__LINE__, "thread %d pass %d", ident, x);
            free(t);
        }
    }

    xs_daemon_close(h);

    return 0;
}
예제 #5
0
static void write_test_device(char *device){
	char *buf;
	int src;
	int out;
	int size = 100;
	total_tests++;
	src = open(device, O_WRONLY);
	if(src < 0){
		fail_test("Device failed to open");
		return;
	}
	buf = (char *) malloc(sizeof(char)* (size+1));
	out = write(src, buf, size);
	total_tests++;
	if(out != size){
		fail_test("Buffer wasn't written properly");
	}
	free(buf);
	close(src);
}
예제 #6
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
static void
xs_write_expected_error(unsigned code, const char *path, const char *data,
                        DWORD e)
{
    DWORD err;

    if (xs_write(xs_handle, path, data)) {
        fail_test(code, "managed to write %s to %s\n", data, path);
    } else {
        err = GetLastError();
        if (e != err) {
            fail_test(code,
                      "write %s to %s failed with %d, should have failed with %d",
                      data,
                      path,
                      err,
                      e);
        }
    }
}
예제 #7
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
static void
xs_read_expected_error(unsigned code, const char *path, DWORD e)
{
    char *t;
    DWORD err;

    t = xs_read(xs_handle, path, NULL);
    if (t) {
        fail_test(code, "managed to read %s (%s)\n", path, t);
        free(t);
    } else {
        err = GetLastError();
        if (e != err) {
            fail_test(code,
                      "reading %s failed with %d, should have failed with %d",
                      path,
                      err,
                      e);
        }
    }
}
예제 #8
0
파일: dirent-test.c 프로젝트: Henauxg/minix
int setup_test(void)
{
    int i;

    fprintf(stderr, "Creating test directory %s ...\n", TESTDIR);

    if (_mkdir(TESTDIR))
        fail_test("Can't create test directory \"" TESTDIR "\"");

    if (_chdir(TESTDIR))
        fail_test("Can't change to test directory");

    for (i=0; i < n_dir_entries; i++) {
        if (touch(dir_entries[i]))
            fail_test("Can't create test file '%s'", dir_entries[i]);
    }

    fprintf(stderr, "Done with test setup.\n");

    return 0;
}
예제 #9
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
static void
test_many_watches(void)
{
    HANDLE events[64];
    int handles[64];
    int i;
    char buf[64];

    for (i = 0; i < 64; i++) {
        events[i] = CreateEvent(NULL, FALSE, FALSE, NULL);
        if (events[i] == INVALID_HANDLE_VALUE)
            win_err(0, "CreateEvent() %d in test_many_watches", i);
    }
    for (i = 0; i < 64; i++) {
        sprintf(buf, "data/test/key%d", i);
        handles[i] = xs_watch(xs_handle, buf, events[i]);
        if (handles[i] == -1) {
            fail_test(__LINE__, "couldn't watch %s: %d", buf,
                      GetLastError());
        } else {
            /* Wait for the watch to go idle. */
            while (WaitForSingleObject(events[i], 100) != WAIT_TIMEOUT)
                ;
        }
    }
    /* Make sure that the watches all fire. */
    for (i = 0; i < 64; i++) {
        sprintf(buf, "data/test/key%d", i);
        xs_write(xs_handle, buf, "foo");
        if (WaitForSingleObject(events[i], 100) != WAIT_OBJECT_0)
            fail_test(__LINE__, "Watch %d on %s failed to fire", i, buf);
    }

    /* Cancel the watches and close the events. */
    for (i = 0; i < 64; i++) {
        if (handles[i] >= 0)
            xs_unwatch(xs_handle, handles[i]);
        CloseHandle(events[i]);
    }
}
예제 #10
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
static void
xs_ls_expected_error(unsigned code, const char *path, DWORD e)
{
    char **contents;
    unsigned count;
    DWORD err;

    contents = xs_directory(xs_handle, path, &count);
    if (contents) {
        fail_test(code, "managed to ls %s (%d)\n", path, count);
        free(contents);
    } else {
        err = GetLastError();
        if (e != err) {
            fail_test(code,
                      "ls %s failed with %d, should have failed with %d",
                      path,
                      err,
                      e);
        }
    }
}
예제 #11
0
static int sweep_dir(string dir, int when, int verbose, int flag, int test) {
   string *contents;
   int loop, dinged;
 
   if(!directory_exists(dir))  return 0;
 
   if(verbose)  write(bold("Sweeping: " + dir) + "\n");
 
   dinged = 0 ;
   contents = get_dir(dir);

   if(!contents || !sizeof(contents))  return 0;

   //	Loop through contents of the subdirectory check for compliance.
 
    for(loop=0; loop<sizeof(contents); loop++) {
	if(fail_test(dir, contents[loop], when, flag)) {
	    dinged ++ ;
        call_out( "remove_user", dinged * USER_CALL_TIME, contents[loop],
					verbose, flag, test );
	   }
	}
return 1; }
예제 #12
0
void orbital_selector_test::test_2() {

    static const char *testname = "orbital_selector_test::test_2()";

    //
    // Test setting up a orbital_selector with some elements selected
    //

    size_t n = 10;

    orbital_selector s(n);
    s.select(true, n-3, n, 1, true);
    s.select(false, 0, 4);

    if (s.n_indexes() != n) {
        fail_test(testname, __FILE__, __LINE__, "# indexes");
    }
    if (s.n_selected() != 7) {
        fail_test(testname, __FILE__, __LINE__, "# selected");
    }
    if (s.n_selected(true) != 3) {
        fail_test(testname, __FILE__, __LINE__, "# selected occ");
    }
    if (s.n_selected(false) != 4) {
        fail_test(testname, __FILE__, __LINE__, "# selected vir");
    }
    std::vector<size_t> indexes = s.get_selected();
    if (indexes.size() != 7) {
        fail_test(testname, __FILE__, __LINE__, "# indexes");
    }
    for (size_t i = 0; i < 3; i++) {
        if (indexes[i] != n - i - 1)
            fail_test(testname, __FILE__, __LINE__, "i");
    }
    for (size_t i = 3; i < 6; i++) {
        if (indexes[i] != i - 3)
            fail_test(testname, __FILE__, __LINE__, "i");
    }

}
예제 #13
0
void orbital_selector_test::test_3() {

    static const char *testname = "orbital_selector_test::test_5()";

    //
    // Test deselecting a previously selected element
    //

    size_t n = 10;

    orbital_selector s(n);
    s.select(true, 2, 6);
    s.select(false, 6, 9);
    s.deselect(7);

    if (s.n_indexes() != n) {
        fail_test(testname, __FILE__, __LINE__, "# indexes");
    }
    if (s.n_selected() != 6) {
        fail_test(testname, __FILE__, __LINE__, "# selected");
    }
    if (s.all_selected() || s.none_selected()) {
        fail_test(testname, __FILE__, __LINE__, "# selected.");
    }
    std::vector<size_t> indexes = s.get_selected();
    if (indexes.size() != 6) {
        fail_test(testname, __FILE__, __LINE__, "# indexes");
    }
    for (size_t i = 0; i < 4; i++) {
        if (indexes[i] != i + 2)
            fail_test(testname, __FILE__, __LINE__, "indexes[i]");
    }
    if (indexes[4] != 6) {
        fail_test(testname, __FILE__, __LINE__, "indexes[4]");
    }
    if (indexes[5] != 8) {
        fail_test(testname, __FILE__, __LINE__, "indexes[5]");
    }
}
예제 #14
0
// main() has a brief setup and starts one background thread.
// then it enters one big while loop for testing multiple capes.
int main(){
	int ret;
	float volt;
	imu_data_t data; // not really used, just necessary to test imu
	// use defaults for now, except also enable magnetometer.
	imu_config_t conf = get_default_imu_config();
	conf.enable_magnetometer=1;

	// counters for how many pass and fail
	num_passes = 0;
	num_fails = 0;

	// initialize_cape, this should never fail unless software is not set up
	// in which case a useful error message should be printed out.
	if(initialize_cape()<0){
		printf("initialize_cape() failed, this is a software issue,\n");
		printf("not a hardware issue. Try running install.sh and restart\n");
		return -1;
	}

	// set up the button handlers once
	set_pause_pressed_func(&on_pause_pressed);
	set_pause_released_func(&on_pause_released);
	set_mode_pressed_func(&on_mode_pressed);
	set_mode_released_func(&on_mode_released);

	// start blinking thread for 6V test
	pthread_create(&blinking_thread, NULL, blinking_function, (void*) NULL);

	// print welcome
	clear_screen();
	goto_line(0);
	printf("Welcome to the Robotics Cape tester!\n\n");
	printf("this will walk you through testing multiple capes and keep\n");
	printf("track of how many pass and fail.\n");
	printf("Closing the program erases the pass/fail count.\n\n");
	printf("Press enter to begin, anything else to quit.\n");
	if(continue_or_quit()<1){
		goto END;
	}

	/***************************************************************************
	* Begin main while loop
	***************************************************************************/
	while(get_state()!=EXITING){
		line = 0; // reset current printing line to top of terminal
		set_led(RED,OFF);
		set_led(GREEN,OFF);
		
		// clear screen and print pass/fail header
		clear_screen();
		goto_line(line);
		printf("passes: %d  fails: %d\n", num_passes, num_fails);
		line+=2;
		
		
		goto_line(INSTRUCTION_LINE-1);
		printf("*******************************************************************\n");
		printf("Place a new cape in the test jig but don't connect anything else.\n");
		printf("Press any key to start test.\n");
		
		// wait to start test
		if(continue_or_quit()<0){
			goto END;
		}

		/***********************************************************************
		* begin list of tests
		***********************************************************************/
		// make sure 12V DC supply is disconnected
CHECK_DC_DISCONNECT:
		volt = get_dc_jack_voltage();
		if(volt>2.0){
			clear_instruction_area();
			printf("Voltage detected on the DC jack input. This is supposed to be\n");
			printf("disconnected for this part of the test.\n");
			printf("Disconnect and hit ENTER to continue\n");
			printf("If the DC supply was disconnected, there may be a problem with resistors\n");
			printf("R1 or R14, press any key other than ENTER to FAIL this test.\n");
			ret = continue_or_quit();
			if(ret==1) goto CHECK_DC_DISCONNECT;
			else if(ret<0) goto END;
			else{
				goto_line(line);
				printf("FAILED	DC JACK VOLTAGE TEST\n");
				line++;
				fail_test();
				continue;
			}
		}

		// test imu
		ret = initialize_imu(&data, conf);
		power_off_imu();
		goto_line(line);
		line++;
		if(ret<0){
			printf("FAILED	MPU9250 IMU\n");
			fail_test();
			continue; // go to beginning to test next cape
		}
		printf("PASSED	MPU9250 IMU\n");

		// test barometer
		ret = initialize_barometer(BMP_OVERSAMPLE_16,BMP_FILTER_OFF);
		power_off_barometer();
		goto_line(line);
		line++;
		if(ret<0){
			printf("FAILED	BMP280 BAROMETER\n");
			fail_test();
			continue; // go to beginning to test next cape
		}
		printf("PASSED	BMP280 BAROMETER\n");

		// test buttons/LEDS
		clear_instruction_area();
		printf("Press the PAUSE button on cape, the RED led should light up.\n");
		printf("Press the MODE button on cape, the GREEN led should light up.\n");
		printf("Press ENTER to indicate the buttons/leds work\n");
		printf("Press any other key to indicate a failure\n");
		ret = continue_or_quit();
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	BUTTON/LED\n");
			fail_test();
			continue;
		}
		else if(ret<0) goto END;
		printf("PASSED	BUTTON/LED\n");

		// DC power jack ADC check
		clear_instruction_area();
		printf("Plug in the 12V power supply, GREEN CHG LED should turn on.\n");
		printf("Press ENTER if the GREEN CHG LED turns on\n");
		printf("Press any other key if not\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	CHARGER\n");
			printf("CHG_IC may be bad.\n");
			fail_test();
			continue;
		}
		printf("PASSED	CHARGER\n");
		volt = get_dc_jack_voltage();
		if(volt<11.0 || volt>13.0){
			printf("FAILED	12V DC VOLTAGE\n");
			printf("measuring %0.2fV at DC jack, should be roughly 12V\n", volt);
			printf("Resistors R1 or R14 may be bad, shorted, or missing.\n");
			fail_test();
			continue;
		}
		line++;
		printf("PASSED	12V DC VOLTAGE\n");

		// 5V regulator test
		clear_instruction_area();
		printf("Plug in the 4-pin dongle to PWR socket\n");
		printf("Press ENTER if the dongle LED lights up, any other key if not.\n");
		ret = continue_or_quit();
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	5V REGULATOR\n");
			printf("Diode D3 or IC 5VREG may be bad\n");
			fail_test();
			continue;
		}
		else if(ret<0) goto END;
		printf("PASSED	5V REGULATOR\n");

		// battery ADC check
		clear_instruction_area();
		printf("Plug in 2-cell battery and press any key to continue\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		volt = get_battery_voltage();
		goto_line(line);
		line++;
		if(volt<5.0 || volt>9.0){
			printf("FAILED	BATTERY VOLTAGE\n");
			printf("measuring %0.2fV at battery, should be between 6 and 8.4\n", volt);
			printf("Resistors R19 or R25 may be bad, shorted, or missing.\n");
			fail_test();
			continue;
		}
		printf("PASSED	BATTERY VOLTAGE\n");

		// battery discharge check
		clear_instruction_area();
		printf("Disconnect the 12V DC power supply.\n");
		printf("If 4-pin dongle LED is still lit, press ENTER\n");
		printf("Otherwise press any other key.\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	BATTERY DISCHARGE\n");
			printf("Diode D2, or mosfet Q3 are bad.\n");
			fail_test();
			continue;
		}
		printf("PASSED	BATTERY DISCHARGE\n");

		// 6V regulator check
		clear_instruction_area();
		printf("Plug in the 3-pin dongle into any of the 8 servo channels.\n");
		printf("If the dongle LED is blinking press ENTER.\n");
		printf("Otherwise press any other key.\n");
		ret = continue_or_quit();
		if(ret<0) goto END;
		goto_line(line);
		line++;
		if(ret==0){
			printf("FAILED	6VREG\n");
			printf("AOZ1284PI 6VREG or supporting components are bad.\n");
			fail_test();
			continue;
		}
		printf("PASSED	6VREG CHECK\n");

		// END OF TESTING THIS CAPE, PASSED!!!
		num_passes++;
		printf("COMPLETE TEST PASSED\n");
		goto_line(0);
		printf("passes: %d  fails: %d\n", num_passes, num_fails);
		clear_instruction_area();
		printf("Press any key to continue with next cape\n");
		continue_or_quit();
		if(ret<0) goto END;
		// now loop back to test next cape

	} // end while(get_state()!= EXITING)

		
	// if we got here there was a critical error or user hit ctrl+c
END:
	pthread_join(blinking_thread, NULL);
	disable_servo_power_rail();
	cleanup_cape();
	clear_screen();
	return 0;
}
예제 #15
0
파일: xstest.c 프로젝트: OpenXT/xc-windows
int __cdecl
main()
{
    char *vm_path, *uuid, *t;
    size_t l;
    char **contents;
    unsigned count;
    HANDLE xs_handle2;
    HANDLE event;
    HANDLE event2;
    int watch_h;
    int watch_h2;
    int i;
    DWORD status;

    xs_handle = xs_domain_open();
    if (!xs_handle)
        win_err(1, "openning xenstore interface");

    /* Try to give ourselves a clean place to start */
    xs_remove(xs_handle, "data/test");

    /* Check basic xenstore reads with relative path... */
    vm_path = xs_read(xs_handle, "vm", NULL);
    if (!vm_path)
        win_err(1, "reading vm path");
    if (vm_path[0] != '/') {
        fail_test(__LINE__, "expected vm path to be absolute, got %s",
                  vm_path);
    }

    /* and with an absolute path. */
    uuid = gather_read(&l, vm_path, "uuid", NULL);
    if (!uuid)
        win_err(1, "reading uuid");
    if (l != 36) {
        fail_test(__LINE__, "uuid length was %d bytes, expected 36");
    }
    if (strlen(uuid) != 36) {
        fail_test(__LINE__,
                  "uuid was %s, not right length (%d, should be 36), returned length %d",
                  uuid,
                  strlen(uuid),
                  l);
    }

    /* Make sure read error sets a suitable code. */
    xs_read_expected_error(__LINE__, "non_existent", ERROR_FILE_NOT_FOUND);
    xs_read_expected_error(__LINE__, "invalid\\path",
                           ERROR_INVALID_PARAMETER);
    xs_read_expected_error(__LINE__, "/local/domain/0/name",
                           ERROR_ACCESS_DENIED);

    /* Test basic xs_write functionality. */
    if (!xs_write(xs_handle, "data/test/key1", "data1")) {
        fail_test(__LINE__, "write data/test/key1 failed with %lx",
                  GetLastError());
    } else {
        t = xs_read(xs_handle, "data/test/key1", &l);
        if (!t) {
            fail_test(__LINE__, "error reading from data/test/key1: %lx",
                      GetLastError());
        } else {
            if (l != 5) {
                fail_test(__LINE__,
                          "manifest length wrong reading data/test/key1: %d should be 5.",
                          l);
            }
            if (strcmp(t, "data1")) {
                fail_test(__LINE__,
                          "got wrong data reading data/test/key1: %s should be data1.",
                          t);
            }
            free(t);
        }
    }

    xs_write_expected_error(__LINE__, "foo", "bar", ERROR_ACCESS_DENIED);
    xs_write_expected_error(__LINE__, "/foo", "bar", ERROR_ACCESS_DENIED);

    /* Try a very large write and make sure that it fails in the
       expected way. */
    t = malloc(65536);
    memset(t, 'a', 65536);
    t[65535] = 0;
    xs_write_expected_error(__LINE__,"data/test/key1", t,
                            ERROR_DISK_FULL);
    free(t);

    /* Test that read and write work for keys containing nul bytes. */
    if (!xs_write_bin(xs_handle, "data/test/key1", "xxx\0yyy", 7)) {
        fail_test(__LINE__, "failed to write nul bytes (%d)",
                  GetLastError());
    }
    t = xs_read(xs_handle, "data/test/key1", &l);
    if (!t) {
        fail_test(__LINE__, "failed to read nul bytes (%d)",
                  GetLastError());
    } else {
        if (l != 7) {
            fail_test(__LINE__, "read with nuls: expected 7, got %d.\n", l);
        } else if (memcmp(t, "xxx\0yyy", 7)) {
            fail_test(__LINE__, "bad data from read with nuls: %s",
                      t);
        }
        free(t);
    }

    if (!xs_remove(xs_handle, "data/test/key1")) {
        fail_test(__LINE__, "failed to remove data/test/key1 (%d)",
                  GetLastError());
    }

    xs_read_expected_error(__LINE__, "data/test/key1", ERROR_FILE_NOT_FOUND);

    xs_ls_expected_error(__LINE__, "data/test/key1", ERROR_FILE_NOT_FOUND);

    if (!xs_write(xs_handle, "data/test/key1", "data1")) {
        fail_test(__LINE__, "failed to rewrite data/test/key1");
    }

    contents = xs_directory(xs_handle, "data/test/key1", &count);
    if (!contents) {
        fail_test(__LINE__, "failed to ls data/test/key1: %x",
                  GetLastError());
    } else if (count != 0) {
        fail_test(__LINE__, "ls data/test/key1 had %d items", count);
        free(contents);
    } else {
        free(contents);
    }

    if (!xs_write(xs_handle, "data/test/key1/key2", "data2")) {
        fail_test(__LINE__, "failed to rewrite data/test/key1/key2");
    }

    contents = xs_directory(xs_handle, "data/test/key1", &count);
    if (!contents) {
        fail_test(__LINE__, "failed to ls data/test/key1: %x",
                  GetLastError());
    } else if (count != 1) {
        fail_test(__LINE__, "ls data/test/key1 had %d items", count);
        free(contents);
    } else if (strcmp(contents[0], "key2")) {
        fail_test(__LINE__, "ls data/test/key1 gave unexpected result %s",
                  contents[0]);
    }

    xs_remove(xs_handle, "data/test");

    /* Looks like most of the basic functionality works.  Try
     * transactions. */
    xs_handle2 = xs_domain_open();
    if (!xs_handle2) win_err(1, "couldn't re-open domain interface");

    if (!xs_write(xs_handle, "data/test/key1", "before"))
        fail_test(__LINE__, "failed to write to data/test/key1: %x",
                  GetLastError());
    if (!xs_transaction_start(xs_handle2))
        win_err(1, "couldn't open a transaction on second handle");
    if (!xs_write(xs_handle2, "data/test/key1", "after"))
        fail_test(__LINE__, "failed to write to data/test/key1 under transaction: %x",
                  GetLastError());
    if (!xs_transaction_end(xs_handle2, FALSE))
        fail_test(__LINE__, "failed to write to end transaction: %x",
                  GetLastError());
    if (strcmp(xs_read(xs_handle, "data/test/key1", NULL), "after"))
        fail_test(__LINE__, "transaction didn't stick");

    /* Now try aborting the transaction. */
    if (!xs_write(xs_handle, "data/test/key1", "before"))
        fail_test(__LINE__, "failed to write to data/test/key1: %x",
                  GetLastError());
    if (!xs_transaction_start(xs_handle2))
        win_err(1, "couldn't open a transaction on second handle");
    if (!xs_write(xs_handle2, "data/test/key1", "after"))
        fail_test(__LINE__, "failed to write to data/test/key1 under transaction: %x",
                  GetLastError());
    if (!xs_transaction_end(xs_handle2, TRUE))
        fail_test(__LINE__, "failed to write to end transaction: %x",
                  GetLastError());
    if (strcmp(xs_read(xs_handle, "data/test/key1", NULL), "before"))
        fail_test(__LINE__, "transaction didn't abort");

    /* Try to arrange that the transaction fails. */
    if (!xs_write(xs_handle, "data/test/key1", "before"))
        fail_test(__LINE__, "failed to write to data/test/key1: %x",
                  GetLastError());
    if (!xs_transaction_start(xs_handle2))
        win_err(1, "couldn't open a transaction on second handle");
    if (!xs_write(xs_handle2, "data/test/key1", "after"))
        fail_test(__LINE__, "failed to write to data/test/key1 under transaction: %x",
                  GetLastError());
    if (!xs_write(xs_handle, "data/test/key1", "other"))
        fail_test(__LINE__, "failed to write to data/test/key1: %x",
                  GetLastError());
    if (xs_transaction_end(xs_handle2, FALSE))
        fail_test(__LINE__, "transaction succeeded when it shouldn't",
                  GetLastError());
    if (strcmp(xs_read(xs_handle, "data/test/key1", NULL), "other"))
        fail_test(__LINE__, "transaction did something strange");


    if (!xs_write(xs_handle, "data/test/key1", "before1"))
        fail_test(__LINE__, "failed to write to data/test/key1: %x",
                  GetLastError());
    if (!xs_write(xs_handle, "data/test/key2", "before2"))
        fail_test(__LINE__, "failed to write to data/test/key2: %x",
                  GetLastError());
    if (!xs_transaction_start(xs_handle2))
        win_err(1, "couldn't open a transaction on second handle");
    if (!xs_write(xs_handle2, "data/test/key1", "after"))
        fail_test(__LINE__, "failed to write to data/test/key1 under transaction: %x",
                  GetLastError());
    t = xs_read(xs_handle2, "data/test/key2", NULL);
    if (!t) {
        fail_test(__LINE__,
                  "failed to read data/test/key2 under transaction: %x",
                  GetLastError());
    } else {
        if (strcmp(t, "before2"))
            fail_test(__LINE__,
                      "got wrong thing reading dtaa/test/key2 (%s)",
                      t);
        free(t);
    }
    if (!xs_write(xs_handle, "data/test/key2", "other"))
        fail_test(__LINE__, "failed to write to data/test/key1: %x",
                  GetLastError());
    if (xs_transaction_end(xs_handle2, FALSE))
        fail_test(__LINE__, "transaction succeeded when it shouldn't",
                  GetLastError());
    if (strcmp(xs_read(xs_handle, "data/test/key1", NULL), "before1"))
        fail_test(__LINE__, "transaction did something strange");

    xs_daemon_close(xs_handle2);

    /* Try a couple of transaction error cases. */
    xs_handle2 = xs_domain_open();
    if (!xs_handle2) win_err(1, "couldn't re-open domain interface a second time");
    if (!xs_transaction_start(xs_handle2))
        win_err(1, "couldn't open a transaction for re-test");
    if (xs_transaction_start(xs_handle2)) {
        fail_test(__LINE__, "openned two transactions on same handle");
    }
    xs_daemon_close(xs_handle2);

    xs_handle2 = xs_domain_open();
    if (!xs_handle2) win_err(1, "couldn't re-open domain interface a third time");
    if (xs_transaction_end(xs_handle2, FALSE)) {
        fail_test(__LINE__, "ended transaction without starting it");
    }
    if (!xs_transaction_start(xs_handle2))
        win_err(1, "couldn't open a transaction for re-test");
    if (!xs_transaction_end(xs_handle2, FALSE))
        fail_test(__LINE__, "failed to end transaction");
    if (xs_transaction_end(xs_handle2, FALSE)) {
        fail_test(__LINE__, "double-ended transaction");
    }
    xs_daemon_close(xs_handle2);


    /* Transactions appear to be working, at least in their most basic
       form.  Have a go at watches. */
    event = CreateEvent(NULL, FALSE, FALSE, NULL);
    watch_h = xs_watch(xs_handle, "data/test/key1", event);
    if (watch_h < 0) {
        fail_test(__LINE__, "couldn't watch data/test/key1");
    } else {
        while (WaitForSingleObject(event, 100) != WAIT_TIMEOUT)
            ;
        xs_write(xs_handle, "data/test/key1", "foo");
        if (WaitForSingleObject(event, INFINITE) != WAIT_OBJECT_0)
            fail_test(__LINE__, "failed wait for data/test/key1: %x",
                      GetLastError());
        xs_write(xs_handle, "data/test/key1", "foo");
        if (WaitForSingleObject(event, INFINITE) != WAIT_OBJECT_0)
            fail_test(__LINE__, "failed wait for data/test/key1: %x",
                      GetLastError());
        xs_write(xs_handle, "data/test/key1", "foo");
        if (WaitForSingleObject(event, INFINITE) != WAIT_OBJECT_0)
            fail_test(__LINE__, "failed wait for data/test/key1: %x",
                      GetLastError());
        status = WaitForSingleObject(event, 2000);
        if (status != WAIT_TIMEOUT)
            fail_test(__LINE__,
                      "should have timed out waiting for data/test/key1 (%d, %d)",
                      status,
                      GetLastError());

        if (!xs_unwatch(xs_handle, watch_h))
            fail_test(__LINE__, "failed to unwatch");
    }

    /* Create two watches on the same key, kill one of them, and then
       make sure that the other one still works. */
    watch_h = xs_watch(xs_handle, "data/test/key1/subkey", event);
    if (watch_h < 0) {
        fail_test(__LINE__, "couldn't watch data/test/key1/subkey");
    } else {
        event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
        watch_h2 = xs_watch(xs_handle, "data/test/key1/subkey", event);
        if (watch_h2 < 0) {
            fail_test(__LINE__, "couldn't double watch data/test/key1/subkey");
        } else {
            if (!xs_unwatch(xs_handle, watch_h2))
                fail_test(__LINE__, "failed to unwatch h2");
            ResetEvent(event);
            xs_remove(xs_handle, "data/test/key1");
            if (WaitForSingleObject(event, 5000) != WAIT_OBJECT_0)
                fail_test(__LINE__, "failed wait for data/test/key1: %x",
                          GetLastError());
            if (!xs_unwatch(xs_handle, watch_h))
                fail_test(__LINE__, "failed to unwatch");
        }
    }

    /* Watch a node, then modify it in a transaction, and check that
       the watch fires. */
    watch_h = xs_watch(xs_handle, "data/test/key1", event);
    if (watch_h < 0) {
        fail_test(__LINE__, "couldn't watch data/test/key1");
    } else {
        for (i = 0; i < 100; i++) {
            ResetEvent(event);
            do {
                if (!xs_transaction_start(xs_handle))
                    win_err(1, "couldn't open a transaction for watch test");
                xs_write(xs_handle, "data/test/key1", "foo");
            } while (!xs_transaction_end(xs_handle, FALSE));
            if (WaitForSingleObject(event, 5000) != WAIT_OBJECT_0)
                fail_test(__LINE__, "failed wait for data/test/key1(%d): %x",
                          i, GetLastError());
        }
        if (!xs_unwatch(xs_handle, watch_h))
            fail_test(__LINE__, "failed to unwatch");
    }

    /* Make a lot of watches, make sure they all work. */
    test_many_watches();

    /* Try some different sized requests */
    test_write_sizes(4096);

    xs_daemon_close(xs_handle);

    run_stress();

    if (failed) {
        printf("failed\n");
        return 1;
    } else {
        printf("passed\n");
        return 0;
    }
}
예제 #16
0
파일: utils.c 프로젝트: loudambiance/rirc
void
test_avl(void)
{
	/* Test AVL tree functions */

	avl_node *root = NULL;

	/* Insert strings a-z, zz-za, aa-az to hopefully excersize all combinations of rotations */
	const char **ptr, *strings[] = {
		"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
		"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
		"zz", "zy", "zx", "zw", "zv", "zu", "zt", "zs", "zr", "zq", "zp", "zo", "zn",
		"zm", "zl", "zk", "zj", "zi", "zh", "zg", "zf", "ze", "zd", "zc", "zb", "za",
		"aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am",
		"an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw", "ax", "ay", "az",
		NULL
	};

	int ret, count = 0;

	/* Add all strings to the tree */
	for (ptr = strings; *ptr; ptr++) {
		if (!avl_add(&root, *ptr, NULL))
			fail_testf("avl_add() failed to add %s", *ptr);
		else
			count++;
	}

	/* Check that all were added correctly */
	if ((ret = _avl_count(root)) != count)
		fail_testf("_avl_count() returned %d, expected %d", ret, count);

	/* Check that the binary properties of the tree hold */
	if (!_avl_is_binary(root))
		fail_test("_avl_is_binary() failed");

	/* Check that the height of root stays within the mathematical bounds AVL trees allow */
	double max_height = 1.44 * log2(count + 2) - 0.328;

	if ((ret = _avl_height(root)) >= max_height)
		fail_testf("_avl_height() returned %d, expected strictly less than %f", ret, max_height);

	/* Test adding a duplicate and case sensitive duplicate */
	if (avl_add(&root, "aa", NULL) && count++)
		fail_test("avl_add() failed to detect duplicate 'aa'");

	if (avl_add(&root, "aA", NULL) && count++)
		fail_test("avl_add() failed to detect case sensitive duplicate 'aA'");

	/* Delete about half of the strings */
	int num_delete = count / 2;

	for (ptr = strings; *ptr && num_delete > 0; ptr++, num_delete--) {
		if (!avl_del(&root, *ptr))
			fail_testf("avl_del() failed to delete %s", *ptr);
		else
			count--;
	}

	/* Check that all were deleted correctly */
	if ((ret = _avl_count(root)) != count)
		fail_testf("_avl_count() returned %d, expected %d", ret, count);

	/* Check that the binary properties of the tree still hold */
	if (!_avl_is_binary(root))
		fail_test("_avl_is_binary() failed");

	/* Check that the height of root is still within the mathematical bounds AVL trees allow */
	max_height = 1.44 * log2(count + 2) - 0.328;

	if ((ret = _avl_height(root)) >= max_height)
		fail_testf("_avl_height() returned %d, expected strictly less than %f", ret, max_height);

	/* Test deleting string that was previously deleted */
	if (avl_del(&root, *strings))
		fail_testf("_avl_del() should have failed to delete %s", *strings);
}
예제 #17
0
파일: utils.c 프로젝트: loudambiance/rirc
void
test_parse(void)
{
	/* Test the IRC message parsing function */

	parsed_mesg p;

	/* Test ordinary message */
	char mesg1[] = ":[email protected] CMD args :trailing";

	if ((parse(&p, mesg1)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     "nick");
	assert_strcmp(p.hostinfo, "*****@*****.**");
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   "args");
	assert_strcmp(p.trailing, "trailing");

	/* Test no nick/host */
	char mesg2[] = "CMD arg1 arg2 :  trailing message  ";

	if ((parse(&p, mesg2)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     NULL);
	assert_strcmp(p.hostinfo, NULL);
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   "arg1 arg2");
	assert_strcmp(p.trailing, "  trailing message  ");

	/* Test the 15 arg limit */
	char mesg3[] = "CMD a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 :trailing message";

	if ((parse(&p, mesg3)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     NULL);
	assert_strcmp(p.hostinfo, NULL);
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   "a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14");
	assert_strcmp(p.trailing, "a15 :trailing message");

	/* Test ':' can exist in args */
	char mesg4[] = ":[email protected] CMD arg:1:2:3 arg:4:5:6 :trailing message";

	if ((parse(&p, mesg4)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     "nick");
	assert_strcmp(p.hostinfo, "*****@*****.**");
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   "arg:1:2:3 arg:4:5:6");
	assert_strcmp(p.trailing, "trailing message");

	/* Test no args */
	char mesg5[] = ":[email protected] CMD :trailing message";

	if ((parse(&p, mesg5)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     "nick");
	assert_strcmp(p.hostinfo, "*****@*****.**");
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   NULL);
	assert_strcmp(p.trailing, "trailing message");

	/* Test no trailing */
	char mesg6[] = ":[email protected] CMD arg1 arg2 arg3";

	if ((parse(&p, mesg6)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     "nick");
	assert_strcmp(p.hostinfo, "*****@*****.**");
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   "arg1 arg2 arg3");
	assert_strcmp(p.trailing, NULL);

	/* Test no user */
	char mesg7[] = ":[email protected] CMD arg1 arg2 arg3";

	if ((parse(&p, mesg7)) == NULL)
		fail_test("Failed to parse message");
	assert_strcmp(p.from,     "nick");
	assert_strcmp(p.hostinfo, "hostname.domain");
	assert_strcmp(p.command,  "CMD");
	assert_strcmp(p.params,   "arg1 arg2 arg3");
	assert_strcmp(p.trailing, NULL);

	/* Error: empty message */
	char mesg8[] = "";

	if ((parse(&p, mesg8)) != NULL)
		fail_test("parse() was expected to fail");

	/* Error: no command */
	char mesg9[] = ":[email protected]";

	if ((parse(&p, mesg9)) != NULL)
		fail_test("parse() was expected to fail");
}
예제 #18
0
/* Test the btowc() function for a few locales with known character sets.  */
int
main (int argc, char** argv)
{
  int result = 0;

  current_locale = setlocale (LC_ALL, "en_US.ANSI_X3.4-1968");
  if (current_locale == NULL)
    {
      puts ("cannot set locale \"en_US.ANSI_X3.4-1968\"");
      result = 1;
    }
  else
    {
      int c;

      for (c = 0; c < 128; ++c)
	result |= ok_test (c, c);

      for (c = 128; c < 256; ++c)
	result |= fail_test (c);

      result |= eof_test ();
    }

  current_locale = setlocale (LC_ALL, "de_DE.ISO-8859-1");
  if (current_locale == NULL)
    {
      puts ("cannot set locale \"de_DE.ISO-8859-1\"");
      result = 1;
    }
  else
    {
      int c;

      for (c = 0; c < 256; ++c)
	result |= ok_test (c, c);

      result |= eof_test ();
    }

  current_locale = setlocale (LC_ALL, "de_DE.UTF-8");
  if (current_locale == NULL)
    {
      puts ("cannot set locale \"de_DE.UTF-8\"");
      result = 1;
    }
  else
    {
      int c;

      for (c = 0; c < 128; ++c)
	result |= ok_test (c, c);

      for (c = 128; c < 256; ++c)
	result |= fail_test (c);

      result |= eof_test ();
    }

  current_locale = setlocale (LC_ALL, "hr_HR.ISO-8859-2");
  if (current_locale == NULL)
    {
      puts ("cannot set locale \"hr_HR.ISO-8859-2\"");
      result = 1;
    }
  else
    {
      static const wint_t upper_half[] =
      {
	0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8,
	0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0,
	0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8,
	0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154,
	0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C,
	0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, 0x0110,
	0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, 0x0158,
	0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, 0x0155,
	0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, 0x010D,
	0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111,
	0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159,
	0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
      };
      int c;

      for (c = 0; c < 161; ++c)
	result |= ok_test (c, c);

      for (c = 161; c < 256; ++c)
	result |= ok_test (c, upper_half[c - 161]);

      result |= eof_test ();
    }

  if (result == 0)
    puts ("all OK");

  return result;
}