Exemplo n.º 1
0
void test_get( const char *name, int val )
{
    //test_check_ge(val, 0); // not negative
    printf("%s = %d\n", name, val );
    if( val < 0 )
        test_fail_msg(EINVAL, name);
}
Exemplo n.º 2
0
static errno_t threads_test()
{

    hal_cond_init(&c, "threadTest");
    hal_mutex_init(&m, "threadTest");
    hal_sem_init(&s, "threadTest");

    int i = 40;
    n_t_empty = i;
    while(i-- > 0)
        phantom_create_thread( t_empty, "Empty", 0 );

    pressEnter("will create thread");
    phantom_create_thread( thread1, "__T1__", 0 );
    phantom_create_thread( thread1, "__T2__", 0 );
    //phantom_create_thread( thread1, "__T3__" );

    //phantom_create_thread( t_wait, "__TW__" );
    int tid = hal_start_kernel_thread_arg( t_wait, "__TW__" );

    i = 40;
    while(i-- > 0)
    {
        if(TEST_CHATTY) pressEnter("will yield");
        YIELD();

        if(TEST_CHATTY) printf("!! back in main\n");
    }

    t_kill_thread( tid );
    hal_sleep_msec( 30 );

    thread_stop_request = 1;
    hal_sleep_msec( 10 );

    thread_activity_counter = 0;
    hal_sleep_msec( 1000 );
    if( thread_activity_counter )
    {
        SHOW_ERROR0( 0, "Can't stop thread" );
        return -1;
    }

    while(n_t_empty > 0)
    {
        SHOW_FLOW( 0, "wait for %d threads", n_t_empty );
        hal_sleep_msec(500);
    }

    if(p._ah.refCount != 1)
    {
        SHOW_ERROR( 0, "p._ah.refCount = %d", p._ah.refCount );
        test_fail_msg( -1, "refcount" );
    }
    else
        SHOW_ERROR( 0, "p._ah.refCount = %d, SUCCESS", p._ah.refCount );

    return 0;
}
Exemplo n.º 3
0
int do_test_sem(const char *test_parm)
{
    (void) test_parm;
    printf("Testing semaphores\n");

    hal_sem_init(&test_sem_0, "semTest");



    softirq = hal_alloc_softirq();
    if( softirq < 0 )
        test_fail_msg( 1, "Unable to get softirq" );

    hal_set_softirq_handler( softirq, sem_softirq, 0 );

    //int tid =
    hal_start_kernel_thread_arg( sem_rel, 0 );

    printf("sema wait 1\n");

    // Direct
    sem_released = 0;
    hal_sem_acquire( &test_sem_0 );
    test_check_eq(sem_released,1);

    hal_sleep_msec( 100 );

    printf("sema wait 2\n");

#if TEST_SOFTIRQ
    // Softirq
    sem_released = 0;
    hal_sem_acquire( &test_sem_0 );
    test_check_eq(sem_released,1);
#endif

    hal_sleep_msec( 100 );


    printf("sema timeout\n");
    sem_released = 0;
    hal_start_kernel_thread_arg( sem_etc, 0 );
    hal_sleep_msec( 100 );
    test_check_eq(sem_released,0);
    hal_sleep_msec( 120 );
    test_check_eq(sem_released,1);
    test_check_eq( rc, ETIMEDOUT);


    stop_sem_test = 1;

    printf("Done testing semaphores\n");
    return 0;

}
Exemplo n.º 4
0
static void __cfree(int tobe, int ln)
{
    int real = nfree();

    if( tobe == real )
        return;

    SHOW_ERROR( 0, "free is %d, must be %d, diff = %d  @line %d", real, tobe, real-tobe, ln );

    test_fail_msg( EINVAL, "free count is wrong" );
}
Exemplo n.º 5
0
static void
test_config_check_or_create_data_subdir(void *arg)
{
  or_options_t *options = get_options_mutable();
  char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-0"));
  const char *subdir = "test_stats";
  char *subpath = get_datadir_fname(subdir);
  struct stat st;
  int r;
#if !defined (_WIN32) || defined (WINCE)
  unsigned group_permission;
#endif
  (void)arg;

#if defined (_WIN32) && !defined (WINCE)
  tt_int_op(mkdir(options->DataDirectory), ==, 0);
#else
  tt_int_op(mkdir(options->DataDirectory, 0700), ==, 0);
#endif

  r = stat(subpath, &st);

  // The subdirectory shouldn't exist yet,
  // but should be created by the call to check_or_create_data_subdir.
  test_assert(r && (errno == ENOENT));
  test_assert(!check_or_create_data_subdir(subdir));
  test_assert(is_private_dir(subpath));

  // The check should return 0, if the directory already exists
  // and is private to the user.
  test_assert(!check_or_create_data_subdir(subdir));

#if !defined (_WIN32) || defined (WINCE)
  group_permission = st.st_mode | 0070;
  r = chmod(subpath, group_permission);

  if (r) {
    test_fail_msg("Changing permissions for the subdirectory failed.");
  }

  // If the directory exists, but its mode is too permissive
  // a call to check_or_create_data_subdir should reset the mode.
  test_assert(!is_private_dir(subpath));
  test_assert(!check_or_create_data_subdir(subdir));
  test_assert(is_private_dir(subpath));
#endif

 done:
  rmdir(subpath);
  tor_free(datadir);
  tor_free(subpath);
}
Exemplo n.º 6
0
static void test_one(const char *b, const char *a, const char*expect)
{
    char o[FS_MAX_PATH_LEN*2];

    SHOW_FLOW( 0, "'%s' + '%s'", b, a );

    if( uu_make_absname( o, b, a ) )
        test_fail_msg( EINVAL, "uu_absname failed" );

    if( expect && strcmp( o, expect ) )
    {
        SHOW_ERROR(0, "Expected '%s', got '%s'", expect, o );
        test_fail( EINVAL );
    }

}
Exemplo n.º 7
0
int do_test_01_threads(const char *test_parm)
{
    (void) test_parm;
    printf("Testing thread state integrity\n");

    hal_start_kernel_thread_arg( thread_ones, 0 );
    hal_start_kernel_thread_arg( thread_zeroes, 0 );

    printf("Wait for 01 threads to finish\n");

    while(zo_run)
        hal_sleep_msec(100);


    if(zo_fail)
        test_fail_msg( -1, "data corruption" );

    return 0;
}
Exemplo n.º 8
0
void test_set( const char *name, int ret, int sent )
{
    printf("%s( %2d ) = %d\n", name, sent, ret );
    if( ret < 0 )
        test_fail_msg(EINVAL, name);
}
Exemplo n.º 9
0
int do_test_physmem(const char *test_parm)
{
    (void) test_parm;
#if !defined(ARCH_arm)
    void *va;
    physaddr_t pa;

    char buf[MSIZE];

    hal_pv_alloc( &pa, &va, MSIZE );

    test_check_true( va != 0 );
    test_check_true( pa != 0 );

    memset( va, 0, MSIZE );
    memcpy_p2v( buf, pa, MSIZE );
    if( memnotchar( buf, 0, MSIZE ) )
        test_fail_msg( EINVAL, "not 0");


    memset( buf, 0xFF, MSIZE );
    memcpy_v2p( pa, buf, MSIZE );
    if( memnotchar( va, 0xFF, MSIZE ) )
        test_fail_msg( EINVAL, "not 1");

    memset( va, 0, MSIZE );

    memcpy_v2p( pa, "AAA", 3 );
    if( memnotchar( va, 'A', 3 ) )
        test_fail_msg( EINVAL, "not A");

    if( memnotchar( va+3, 0, MSIZE-3 ) )
        test_fail_msg( EINVAL, "not A0");


    memset( va, 0, MSIZE );

    memcpy_v2p( pa+10, "BBB", 3 );
    if( memnotchar( va+10, 'B', 3 ) )
        test_fail_msg( EINVAL, "not B");

    if( memnotchar( va, 0, 10 ) )
        test_fail_msg( EINVAL, "not B0-");

    if( memnotchar( va+13, 0, MSIZE-13 ) )
        test_fail_msg( EINVAL, "not B0+");


    // Cross page
    memset( va, 0, MSIZE );
#define SH (4096-4)

    memcpy_v2p( pa+SH, "EEEEEEEE", 8 );
    if( memnotchar( va+SH, 'E', 8 ) )
        test_fail_msg( EINVAL, "not E");

    if( memnotchar( va, 0, SH ) )
        test_fail_msg( EINVAL, "not E0-");

    if( memnotchar( va+SH+8, 0, MSIZE-SH-8 ) )
        test_fail_msg( EINVAL, "not E0+");



#if 0 // not impl
    memset( va, 0, MSIZE );

    memset( va+20, 'C', 3 );
    memcpy_p2v( buf, pa+20, 3 );
    if( memnotchar( buf, 'C', 3 ) )
        test_fail_msg( EINVAL, "not C");
#endif

    hal_pv_free( pa, va, MSIZE );
#endif //!defined(ARCH_arm)

    return 0;
}