Example #1
0
int main(int argc, char *argv[])
{
    mps_arena_t arena;
    mps_thr_t thread;

    testlib_init(argc, argv);

    die(mps_arena_create(&arena, mps_arena_class_vm(),
                         testArenaSIZE),
        "arena_create");
    die(mps_thread_reg(&thread, arena), "thread_reg");

    test(arena, mps_class_amc());
    test(arena, mps_class_amcz());
    /* TODO: test(arena, mps_class_ams()); -- see job003738 */
    test(arena, mps_class_awl());
    test(arena, mps_class_lo());

    mps_thread_dereg(thread);
    mps_arena_destroy(arena);

    printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);
    return 0;
}
Example #2
0
/* main -- runs various test scripts
 *
 */
int main(int argc, char *argv[])
{
  testlib_init(argc, argv);

  /* Scripts that should fail (uncomment to show failure is detected) */
  /*testscriptA("C.");*/
  /*testscriptA("b.");*/

  /* The most basic scripts */
  testscriptA(".");
  testscriptA("Cbe.");
  testscriptA("Cbe.Cbe.");

  /* Get messages, but not promptly */
  testscriptA(".Cbe.CbeCbeCbe.");

  /* Ungot messages at ArenaDestroy */
  testscriptA("Cbe");
  testscriptA("Cbe.CbeCbeCbe");

  /* Fail to call mps_message_discard */
  testscriptA("Cbe!");
  testscriptA("Cbe!CbeCbeCbe!");

  /* Simple finalization
   *
   * These tests rely on the particular order in which the "F" command 
   * nulls-out references.  Not every "F" makes an object finalizable.
   * See .keep-alive.
   */
  testscriptA("FFCbffe.");
  testscriptA("FFCbffe.FFCbffe.");
  testscriptA("FFCbffe.FCbe.F.Cbffe.FFCbfe.FF.Cbfffe.");
  
  /* Various other scripts */
  testscriptA("Cbe.FFCbffe.Cbe");

  /* Simulate low memory situations
   *
   * These scripts only work with a manually edited traceanc.c --
   * see TIMCA_remote() above.
   *
   * When TraceIdMessagesCreate is trying to pre-allocate GC messages, 
   * either "0" or "10" makes it fail -- "0" fails the trace start 
   * message alloc, whereas "10" fails the trace end message alloc. 
   * In either case TraceIdMessagesCreate promptly gives up, and 
   * neither start nor end message will be sent for the next trace.
   *
   * See <design/message-gc#lifecycle>.
   */
#if TEST_CONTROLALLOC_FAILURE
  {
    /* ArenaCreate unable to pre-allocate: THESE SHOULD FAIL */
    /* manually edit if(0) -> if(1) to test these */
    if(0) {
      TIMCA_setup("0"); testscriptA("Fail at create 1");
    }
    if(0) {
      TIMCA_setup("10"); testscriptA("Fail at create 2");
    }

    /* ArenaDestroy with no pre-allocated messages */
    TIMCA_setup("20"); testscriptA("Cbe.");
    TIMCA_setup("210"); testscriptA("Cbe.");

    /* Collect with no pre-allocated messages: drops messages, */
    /* hence "C." instead of "Cbe.".  Also, in diagnostic varieties, */
    /* these should produce a "droppedMessages" diagnostic at */
    /* ArenaDestroy. */
    TIMCA_setup("2022"); testscriptA("Cbe.C.Cbe.");
    TIMCA_setup("21022"); testscriptA("Cbe.C.Cbe.");

    /* 2 Collects and ArenaDestroy with no pre-allocated messages */
    TIMCA_setup("2000"); testscriptA("Cbe.C.C.");
    TIMCA_setup("201010"); testscriptA("Cbe.C.C.");
    
    TIMCA_setup("");  /* must reset it! */
  }
#endif

  printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);
  return 0;
}
Example #3
0
int main(int argc, char ** argv) {
  int ii;

  FixedAllocator fa = fixed_allocator_make(sizeof(long), 100, "fa");
  void* last;
  for(ii=0; ii < 100; ++ii) {
    ASSERT((last = fixed_allocator_alloc(fa)) != NULL);
  }

  //ASSERT(fixed_allocator_alloc(fa) == NULL);
  fixed_allocator_free(fa, last);
  ASSERT(fixed_allocator_alloc(fa) != NULL);

  StackAllocator sa = stack_allocator_make(sizeof(long) * 100, "sa");
  for(ii=0; ii < 100; ++ii) {
    ASSERT((last = stack_allocator_alloc(sa, sizeof(long))) != NULL);
  }

  //ASSERT(stack_allocator_alloc(sa, sizeof(long)) == NULL);
  stack_allocator_freeall(sa);
  ASSERT(stack_allocator_alloc(sa, sizeof(long) * 5) != NULL);

  CircularBuffer buffer = circularbuffer_make(100);
  ASSERT(circularbuffer_bytes_writable(buffer) == 100);
  ASSERT(circularbuffer_bytes_readable(buffer) == 0);

  char bytes[100];
  for(ii = 0; ii < 100; ++ii) {
    bytes[ii] = ii;
  }

  circularbuffer_insert(buffer, bytes, 100);
  ASSERT(circularbuffer_bytes_writable(buffer) == 0);
  ASSERT(circularbuffer_bytes_readable(buffer) == 100);

  char morebytes[100];
  circularbuffer_read(buffer, morebytes, 50);
  ASSERT(circularbuffer_bytes_readable(buffer) == 50);
  ASSERT(circularbuffer_bytes_writable(buffer) == 50);
  for(int ii = 0; ii < 50; ++ii) {
    ASSERT(morebytes[ii] == ii);
  }

  circularbuffer_insert(buffer, bytes, 50);
  ASSERT(circularbuffer_bytes_writable(buffer) == 0);
  ASSERT(circularbuffer_bytes_readable(buffer) == 100);

  circularbuffer_read(buffer, morebytes, 100);
  ASSERT(circularbuffer_bytes_writable(buffer) == 100);
  ASSERT(circularbuffer_bytes_readable(buffer) == 0);
  for(int ii = 0; ii < 100; ++ii) {
    if(ii < 50) {
      ASSERT(morebytes[ii] == ii + 50);
    } else {
      ASSERT(morebytes[ii] == ii - 50);
    }
  }

  testlib_init();
  screen_width = 640;
  screen_height = 480;

  game_init();
  agent_init();

  Particle particle = particle_make();
  Enemy enemy = enemy_make((Particle)particle, 100);

  ASSERT(enemy->agent.inbox.head == NULL);
  ASSERT(enemy->agent.outbox.head == NULL);

  agent_update((Agent)enemy);
  ASSERT(enemy->agent.state == ENEMY_IDLE);

  ASSERT(enemy->agent.inbox.head == NULL);
  ASSERT(enemy->agent.outbox.head == NULL);

  Message terminate = message_make(NULL, MESSAGE_TERMINATE, NULL);
  message_postinbox((Agent)enemy, terminate);

  agent_update((Agent)enemy);

  ASSERT(enemy->agent.inbox.head == NULL);
  ASSERT(enemy->agent.outbox.head != NULL);

  Message reply = (Message)dll_remove_tail(&enemy->agent.outbox);
  ASSERT(reply->kind == MESSAGE_TERMINATING);
  ASSERT(enemy->agent.state != ENEMY_MAX);
  message_report_read(reply);
  ASSERT(enemy->agent.state == ENEMY_MAX);

  // now use a collective
  Collective collective = collective_make();
  Agent ca = (Agent)collective;

  ASSERT(ca->inbox.head == NULL);
  ASSERT(ca->outbox.head == NULL);
  ASSERT(dll_count(&collective->children) == 1);

  Dispatcher dispatcher = (Dispatcher)collective->children.head;
  ASSERT(dll_count(&dispatcher->dispatchees) == 0);

  agent_update((Agent)collective);

  ASSERT(ca->inbox.head == NULL);
  ASSERT(ca->outbox.head == NULL);
  ASSERT(dll_count(&collective->children) == 1);

  Message spawn = message_make(NULL, COLLECTIVE_SPAWN_ENEMY, NULL);
  message_postinbox((Agent)collective, spawn);

  agent_update((Agent)collective);

  ASSERT(ca->inbox.head == NULL);
  ASSERT(ca->outbox.head == NULL);
  ASSERT(dll_count(&collective->children) == 2);
  ASSERT(dll_count(&dispatcher->dispatchees) == 1);

  Dispatchee entry = (Dispatchee)dispatcher->dispatchees.head;
  enemy = (Enemy)entry->agent;
  Particle ep = enemy->visual;

  // park a bullet on top of the enemy and see if the notifications
  // flow
  struct ImageResource_ image;
  image.w = 128;
  image.h = 128;

  Particle bullet =
    (Particle)spawn_bullet(&ep->pos, &ep->vel, &image);
  dll_add_head(&player_bullets, (DLLNode)bullet);

  // current update strategy takes two cycles to push through the
  // deletion
  agent_update((Agent)collective);
  agent_update((Agent)collective);

  ASSERT(dll_count(&collective->children) == 1);
  ASSERT(dll_count(&dispatcher->dispatchees) == 0);

  END_MAIN();
}
Example #4
0
JNIEXPORT jint JNICALL JNI_OnLoad( JavaVM *vm, void *pvt ) {
  testlib_init();
  native_init();
  audio_init();
  return JNI_VERSION_1_6;
}