Beispiel #1
0
static void check_test_memory_usage(void)
{
  /* Wait a little bit to let any threads terminate */

  usleep(HALF_SECOND_USEC);

  /* Get the current memory usage */

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_mmafter = mallinfo();
#else
  (void)mallinfo(&g_mmafter);
#endif

  /* Show the change from the previous time */

  printf("\nEnd of test memory usage:\n");
  show_memory_usage(&g_mmprevious, &g_mmafter);

  /* Set up for the next test */

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_mmprevious = g_mmafter;
#else
  memcpy(&g_mmprevious, &g_mmafter, sizeof(struct mallinfo));
#endif

  /* If so enabled, show the use of priority inheritance resources */

  dump_nfreeholders("user_main:");
}
Beispiel #2
0
static void final_memory_usage(FAR const char *msg)
{
  /* Get the current memory usage */

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_composite.mmcurrent = mallinfo();
#else
  (void)mallinfo(&g_composite.mmcurrent);
#endif

  /* Show the change from the previous time */

  printf("\n%s:\n", msg);
  show_memory_usage(&g_composite.mmstart, &g_composite.mmcurrent);
}
Beispiel #3
0
static void check_test_memory_usage(FAR const char *msg)
{
  /* Get the current memory usage */

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_composite.mmcurrent = mallinfo();
#else
  (void)mallinfo(&g_composite.mmcurrent);
#endif

  /* Show the change from the previous time */

  printf("\%s:\n", msg);
  show_memory_usage(&g_composite.mmprevious, &g_composite.mmcurrent);

  /* Set up for the next test */

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_composite.mmprevious = g_composite.mmcurrent;
#else
  memcpy(&g_composite.mmprevious, &g_composite.mmcurrent, sizeof(struct mallinfo));
#endif
}
Beispiel #4
0
static int user_main(int argc, char *argv[])
{
  int i;

  /* Sample the memory usage now */

#ifndef CONFIG_DISABLE_SIGNALS
  usleep(HALF_SECOND_USEC);

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_mmbefore = mallinfo();
  g_mmprevious = g_mmbefore;
#else
  (void)mallinfo(&g_mmbefore);
  memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo));
#endif
#endif

  printf("\nuser_main: Begin argument test\n");
  printf("user_main: Started with argc=%d\n", argc);

  /* Verify passed arguments */

  if (argc != NARGS + 1)
    {
      printf("user_main: Error expected argc=%d got argc=%d\n",
             NARGS+1, argc);
    }

  for (i = 0; i <= NARGS; i++)
    {
      printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]);
    }

  for (i = 1; i <= NARGS; i++)
    {
      if (strcmp(argv[i], g_argv[i-1]) != 0)
        {
          printf("user_main: ERROR argv[%d]:  Expected \"%s\" found \"%s\"\n",
                 i, g_argv[i-1], argv[i]);
        }
    }
  check_test_memory_usage();

  /* Check environment variables */
#ifndef CONFIG_DISABLE_ENVIRON
  show_environment(true, true, true);

  unsetenv(g_var1_name);
  show_environment(false, true, true);
  check_test_memory_usage();

  clearenv();
  show_environment(false, false, false);
  check_test_memory_usage();
#endif

  /* Top of test loop */
  
#if CONFIG_EXAMPLES_OSTEST_LOOPS > 1
  for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++)
#elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0
  for (;;)
#endif
    {
#if CONFIG_NFILE_DESCRIPTORS > 0
      /* Checkout /dev/null */

      printf("\nuser_main: /dev/null test\n");
      dev_null();
      check_test_memory_usage();
#endif

#ifdef  CONFIG_ARCH_FPU
  /* Check that the FPU is properly supported during context switching */

      printf("\nuser_main: FPU test\n");
      fpu_test();
      check_test_memory_usage();
#endif

#ifdef CONFIG_SCHED_WAITPID
      /* Check waitpid() and friends */

      printf("\nuser_main: waitpid test\n");
      waitpid_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthreads and pthread mutex */

      printf("\nuser_main: mutex test\n");
      mutex_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)
      /* Verify recursive mutexes */

      printf("\nuser_main: recursive mutex test\n");
      recursive_mutex_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthread cancellation */

      printf("\nuser_main: cancel test\n");
      cancel_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthreads and semaphores */

      printf("\nuser_main: semaphore test\n");
      sem_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
    /* Verify pthreads and condition variables */

      printf("\nuser_main: condition variable test\n");
#ifdef CONFIG_PRIORITY_INHERITANCE
      printf("\n           Skipping, Test logic incompatible with priority inheritance\n");
#else
      cond_test();
      check_test_memory_usage();
#endif
#endif

#if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK)
      /* Verify pthreads and condition variable timed waits */

      printf("\nuser_main: timed wait test\n");
      timedwait_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD)
      /* Verify pthreads and message queues */

      printf("\nuser_main: message queue test\n");
      mqueue_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD) && !defined(CONFIG_DISABLE_CLOCK)
      /* Verify pthreads and message queues */

      printf("\nuser_main: timed message queue test\n");
      timedmqueue_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_SIGNALS
      /* Verify signal handlers */

      printf("\nuser_main: signal handler test\n");
      sighand_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS)
      /* Verify posix timers */

      printf("\nuser_main: POSIX timer test\n");
      timer_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0
      /* Verify round robin scheduling */

      printf("\nuser_main: round-robin scheduler test\n");
      rr_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthread barriers */

      printf("\nuser_main: barrier test\n");
      barrier_test();
      check_test_memory_usage();
#endif

#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
      /* Verify priority inheritance */

      printf("\nuser_main: priority inheritance test\n");
      priority_inheritance();
      check_test_memory_usage();
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */

#ifdef CONFIG_ARCH_HAVE_VFORK
      printf("\nuser_main: vfork() test\n");
      vfork_test();
#endif

      /* Compare memory usage at time ostest_main started until
       * user_main exits.  These should not be identical, but should
       * be similar enough that we can detect any serious OS memory
       * leaks.
       */

#ifndef CONFIG_DISABLE_SIGNALS
      usleep(HALF_SECOND_USEC);

#ifdef CONFIG_CAN_PASS_STRUCTS
      g_mmafter = mallinfo();
#else
      (void)mallinfo(&g_mmafter);
#endif

      printf("\nFinal memory usage:\n");
      show_memory_usage(&g_mmbefore, &g_mmafter);
#endif
    }

  printf("user_main: Exitting\n");
  return 0;
}
Beispiel #5
0
void Initialize(void)
{
#ifdef CONFIG_EXAMPLES_CC3000_MEM_CHECK
  mmstart = mallinfo();
  memcpy(&mmprevious, &mmstart, sizeof(struct mallinfo));
  show_memory_usage(&mmstart,&mmprevious);
#endif

  uint8_t fancyBuffer[MAC_ADDR_LEN];

  if (isInitialized)
    {
      printf("CC3000 already initialized. Shutting down and restarting...\n");
      wlan_stop();
      usleep(1000000); /* Delay 1s */
    }

  printf("Initializing CC3000...\n");
  CC3000_Init();
#ifdef CONFIG_EXAMPLES_CC3000_STACK_CHECK
  stkmon_disp();
#endif
  printf("  CC3000 init complete.\n");

  if (nvmem_read_sp_version(fancyBuffer) == 0)
    {
      printf("  Firmware version is: ");
      printf("%d", fancyBuffer[0]);
      printf(".");
      printf("%d\n", fancyBuffer[1]);
    }
  else
    {
      printf("Unable to get firmware version. Can't continue.\n");
      return;
    }

#if 0
  if (nvmem_get_mac_address(fancyBuffer) == 0)
    {
      printf("  MAC address: ");
      for (i = 0; i < MAC_ADDR_LEN; i++)
        {
          if (i != 0)
            {
              printf(":");
            }
          printf("%x", fancyBuffer[i]);
        }

      printf("\n");
      isInitialized = true;
    }
  else
    {
      printf("Unable to get MAC address. Can't continue.\n");
    }
#else
    isInitialized = true;
#endif

#ifdef CONFIG_EXAMPLES_CC3000_MEM_CHECK
    mmprevious = mallinfo();
    show_memory_usage(&mmstart,&mmprevious);
#endif
}
Beispiel #6
0
int execute(int cmd)
{
  int ret = 0;
  if (asyncNotificationWaiting)
    {
      asyncNotificationWaiting = false;
      AsyncEventPrint();
    }

  printf("\n");
  switch(cmd)
    {
    case '1':
      Initialize();
      break;

    case '2':
      ShowBufferSize();
      break;

    case '3':
      StartSmartConfig();
      break;

    case '4':
      ManualConnect();
      break;

    case '5':
      ManualAddProfile();
      break;

    case '6':
      ListAccessPoints();
      break;

    case '7':
      ShowInformation();
      break;

    case '8':
     if (!isInitialized)
       {
         Initialize();
       }

#ifdef CONFIG_EXAMPLES_CC3000_MEM_CHECK
      mmprevious= mallinfo();
      show_memory_usage(&mmstart,&mmprevious);
#endif
      shell_main(0, 0);
#ifdef CONFIG_EXAMPLES_CC3000_MEM_CHECK
      mmprevious= mallinfo();
      show_memory_usage(&mmstart,&mmprevious);
#endif
      break;

    case 'q':
    case 'Q':
      ret = 1;
      break;

    default:
      printf("**Unknown command \"%d\" **\n", cmd);
      break;
    }

    return ret;
}
Beispiel #7
0
static int user_main(int argc, char *argv[])
#endif
{
  int i;

  /* Sample the memory usage now */

#ifndef CONFIG_DISABLE_SIGNALS
  usleep(HALF_SECOND_USEC);

#ifdef CONFIG_CAN_PASS_STRUCTS
  g_mmbefore = mallinfo();
  g_mmprevious = g_mmbefore;
#else
  (void)mallinfo(&g_mmbefore);
  memcpy(&g_mmprevious, &g_mmbefore, sizeof(struct mallinfo));
#endif
#endif

  printf("\nuser_main: Begin argument test\n");
  printf("user_main: Started with argc=%d\n", argc);

  /* Verify passed arguments */

  if (argc != NARGS + 1)
    {
      printf("user_main: Error expected argc=%d got argc=%d\n",
             NARGS+1, argc);
    }

  for (i = 0; i <= NARGS; i++)
    {
      printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]);
    }

  for (i = 1; i <= NARGS; i++)
    {
      if (strcmp(argv[i], g_argv[i-1]) != 0)
        {
          printf("user_main: ERROR argv[%d]:  Expected \"%s\" found \"%s\"\n",
                 i, g_argv[i-1], argv[i]);
        }
    }
  check_test_memory_usage();

  /* If retention of child status is enable, then suppress it for this task.
   * This task may produce many, many children (especially if
   * CONFIG_EXAMPLES_OSTEST_LOOPS) and it does not harvest their exit status.
   * As a result, the test may fail inappropriately unless retention of
   * child exit status is disabled.
   *
   * So basically, this tests that child status can be disabled, but cannot
   * verify that status is retained correctly.
   */

#if defined(CONFIG_SCHED_HAVE_PARENT) && defined(CONFIG_SCHED_CHILD_STATUS)
  {
    struct sigaction sa;
    int ret;

    sa.sa_handler = SIG_IGN;
    sa.sa_flags = SA_NOCLDWAIT;
    ret = sigaction(SIGCHLD, &sa, NULL);
    if (ret < 0)
      {
        printf("user_main: ERROR: sigaction failed: %d\n", errno);
      }
  }
#endif

  /* Check environment variables */
#ifndef CONFIG_DISABLE_ENVIRON
  show_environment(true, true, true);

  unsetenv(g_var1_name);
  show_environment(false, true, true);
  check_test_memory_usage();

  clearenv();
  show_environment(false, false, false);
  check_test_memory_usage();
#endif

  /* Top of test loop */

#if CONFIG_EXAMPLES_OSTEST_LOOPS > 1
  for (i = 0; i < CONFIG_EXAMPLES_OSTEST_LOOPS; i++)
#elif CONFIG_EXAMPLES_OSTEST_LOOPS == 0
  for (;;)
#endif
    {
#if CONFIG_NFILE_DESCRIPTORS > 0
      /* Checkout /dev/null */

      printf("\nuser_main: /dev/null test\n");
      dev_null();
      check_test_memory_usage();
#endif

#ifdef  CONFIG_ARCH_FPU
      /* Check that the FPU is properly supported during context switching */

      printf("\nuser_main: FPU test\n");
      fpu_test();
      check_test_memory_usage();
#endif

      /* Checkout task_restart() */

      printf("\nuser_main: task_restart test\n");
      restart_test();
      check_test_memory_usage();

#ifdef CONFIG_SCHED_WAITPID
      /* Check waitpid() and friends */

      printf("\nuser_main: waitpid test\n");
      waitpid_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthreads and pthread mutex */

      printf("\nuser_main: mutex test\n");
      mutex_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)
      /* Verify recursive mutexes */

      printf("\nuser_main: recursive mutex test\n");
      recursive_mutex_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthread cancellation */

      printf("\nuser_main: cancel test\n");
      cancel_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthreads and semaphores */

      printf("\nuser_main: semaphore test\n");
      sem_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
    /* Verify pthreads and condition variables */

      printf("\nuser_main: condition variable test\n");
#ifdef CONFIG_PRIORITY_INHERITANCE
      printf("\n           Skipping, Test logic incompatible with priority inheritance\n");
#else
      cond_test();
      check_test_memory_usage();
#endif
#endif

#if !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
      /* Verify pthreads and condition variable timed waits */

      printf("\nuser_main: timed wait test\n");
      timedwait_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD)
      /* Verify pthreads and message queues */

      printf("\nuser_main: message queue test\n");
      mqueue_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_MQUEUE) && !defined(CONFIG_DISABLE_PTHREAD)
      /* Verify pthreads and message queues */

      printf("\nuser_main: timed message queue test\n");
      timedmqueue_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_SIGNALS
      /* Verify signal handlers */

      printf("\nuser_main: signal handler test\n");
      sighand_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_POSIX_TIMERS) && !defined(CONFIG_DISABLE_SIGNALS)
      /* Verify posix timers */

      printf("\nuser_main: POSIX timer test\n");
      timer_test();
      check_test_memory_usage();
#endif

#if !defined(CONFIG_DISABLE_PTHREAD) && CONFIG_RR_INTERVAL > 0
      /* Verify round robin scheduling */

      printf("\nuser_main: round-robin scheduler test\n");
      rr_test();
      check_test_memory_usage();
#endif

#ifndef CONFIG_DISABLE_PTHREAD
      /* Verify pthread barriers */

      printf("\nuser_main: barrier test\n");
      barrier_test();
      check_test_memory_usage();
#endif

#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_PTHREAD)
      /* Verify priority inheritance */

      printf("\nuser_main: priority inheritance test\n");
      priority_inheritance();
      check_test_memory_usage();
#endif /* CONFIG_PRIORITY_INHERITANCE && !CONFIG_DISABLE_SIGNALS && !CONFIG_DISABLE_PTHREAD */

#if defined(CONFIG_ARCH_HAVE_VFORK) && defined(CONFIG_SCHED_WAITPID) && \
   !defined(CONFIG_DISABLE_SIGNALS)
      printf("\nuser_main: vfork() test\n");
      vfork_test();
#endif

      /* Compare memory usage at time ostest_main started until
       * user_main exits.  These should not be identical, but should
       * be similar enough that we can detect any serious OS memory
       * leaks.
       */

#ifndef CONFIG_DISABLE_SIGNALS
      usleep(HALF_SECOND_USEC);

#ifdef CONFIG_CAN_PASS_STRUCTS
      g_mmafter = mallinfo();
#else
      (void)mallinfo(&g_mmafter);
#endif

      printf("\nFinal memory usage:\n");
      show_memory_usage(&g_mmbefore, &g_mmafter);
#endif
    }

  printf("user_main: Exitting\n");
  return 0;
}