Exemple #1
0
int main(void) {
  volatile0 = 0;
  ac_bool error = AC_FALSE;

  /*
   * Manually test these runtime errors, enable one at a time
   * and compile and run, each statement should fail.
   */
  //ac_static_assert(1 == 0, "ac_static_assert(1 == 0), should always fail");
  //ac_static_assert(volatile0 == 0, "ac_static_assert(volatile0 == 0), should always fail");

  // Expect these asserts to fail, but since our ac_fail_impl
  // does not invoke "stop()" we can use AC_TEST to validate
  // that they failed (returned AC_TRUE) and PASS.
  ac_printf("Expect 5 failures vvvvvvvvvvvvvvvvvvvvvvv\n");
  error |= AC_TEST(ac_fail("failing"));
  error |= AC_TEST(ac_assert(0 == 1));
  error |= AC_TEST(ac_assert(volatile0 == 1));
  error |= AC_TEST(ac_debug_assert(1 == 2));
  error |= AC_TEST(ac_debug_assert(volatile0 == 2));
  ac_printf("Expect 5 failures ^^^^^^^^^^^^^^^^^^^^^^^\n");

  // These should never fail
  ac_static_assert(0 == 0, "ac_static_assert(0 == 0) should never fail");
  error |= AC_TEST(!ac_assert(0 == 0));
  error |= AC_TEST(!ac_assert(volatile0 == 0));

  if (!error) {
    // Succeeded
    ac_printf("OK\n");
  }

  return error;
}
Exemple #2
0
/**
 * Initialize module
 */
void ac_thread_init(ac_u32 max_threads) {
  // Verify that pthread_t is <= sizeof(ac_uptr)
  ac_static_assert(sizeof(pthread_t) <= sizeof(ac_uptr),
      "Expect pthread_t to be the size of a pointer");

  ac_assert(max_threads > 0);

  ac_u32 size = sizeof(ac_threads) + (max_threads * sizeof(ac_tcb));
  pthreads = ac_malloc(size);
  ac_assert(pthreads != AC_NULL);

  pthreads->max_count = max_threads;
  for (ac_u32 i = 0; i < pthreads->max_count; i++) {
    pthreads->tcbs[i].thread_id = AC_THREAD_ID_EMPTY;
  }
}
Exemple #3
0
/**
 * Initialize module
 */
void ac_thread_init(ac_u32 max_threads) {
  // Verify that pthread_t is <= sizeof(ac_uptr)
  ac_static_assert(sizeof(pthread_t) <= sizeof(ac_uptr),
      "Expect pthread_t to be the size of a pointer");

  ac_assert(max_threads > 0);

  // Add one for the "main" thread
  max_threads += 1;

  ac_u32 size = sizeof(ac_threads) + (max_threads * sizeof(ac_tcb));
  pthreads = ac_malloc(size);
  ac_assert(pthreads != AC_NULL);

  pthreads->max_count = max_threads;
  for (ac_u32 i = 0; i < pthreads->max_count; i++) {
    pthreads->tcbs[i].thread_id = AC_THREAD_ID_EMPTY;
  }

  // Initialize pthreads->tcb[0] as main thread
  pthreads->tcbs[0].thread_id = pthread_self();
  pthreads->tcbs[0].entry = AC_NULL;
  pthreads->tcbs[0].entry_arg = AC_NULL;
}