Exemple #1
0
/**
* @fn                   :tc_libc_spawn_posix_spawnattr_dump
* @brief                :Show the current attributes
* @scenario             :It dumps the spawn attributes whose address is passed
* @API's covered        :posix_spawnattr_init,posix_spawnattr_setschedparam, posix_spawnattr_setflags,posix_spawnattr_setschedpolicy, posix_spawnattr_dump
* @Preconditions        :posix_spawnattr_init, posix_spawnattr_setschedparam, posix_spawnattr_setflags,posix_spawnattr_setschedpolicy
* @Postconditions       :none
* @Return               :void
*/
static void tc_libc_spawn_posix_spawnattr_dump(void)
{
	int ret_chk = ERROR;
	pid_t pid;
	posix_spawnattr_t st_attr;

	ret_chk = posix_spawnattr_init(&st_attr);
	TC_ASSERT_EQ("posix_spawnattr_init", ret_chk, OK);

	ret_chk = posix_spawnattr_setschedpolicy(&st_attr, SCHED_RR);
	TC_ASSERT_EQ("posix_spawnattr_setschedpolicy", ret_chk, OK);

	ret_chk = task_spawn(&pid, "spawn_dump", function_name_spawn, NULL, &st_attr, (char *const *)NULL, (char *const *)NULL);
	sleep(SEC_4);
	TC_ASSERT_EQ("task_spawn", ret_chk, OK);

	posix_spawnattr_dump(&st_attr);
	TC_SUCCESS_RESULT();
}
Exemple #2
0
int spawn_main(int argc, char *argv[])
{
  posix_spawn_file_actions_t file_actions;
  posix_spawnattr_t attr;
  FAR const char *filepath;
  pid_t pid;
  int ret;

  /* Initialize the memory monitor */

  mm_initmonitor();

  /* Initialize the ELF binary loader */

  message("Initializing the ELF binary loader\n");
  ret = elf_initialize();
  if (ret < 0)
    {
      err("ERROR: Initialization of the ELF loader failed: %d\n", ret);
      exit(1);
    }

  mm_update(&g_mmstep, "after elf_initialize");

  /* Create a ROM disk for the ROMFS filesystem */

  message("Registering romdisk at /dev/ram%d\n", CONFIG_EXAMPLES_ELF_DEVMINOR);
  ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR, (FAR uint8_t *)romfs_img,
                         NSECTORS(romfs_img_len), SECTORSIZE);
  if (ret < 0)
    {
      err("ERROR: romdisk_register failed: %d\n", ret);
      elf_uninitialize();
      exit(1);
    }

  mm_update(&g_mmstep, "after romdisk_register");

  /* Mount the file system */

  message("Mounting ROMFS filesystem at target=%s with source=%s\n",
         MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH);

  ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs", MS_RDONLY, NULL);
  if (ret < 0)
    {
      err("ERROR: mount(%s,%s,romfs) failed: %s\n",
          CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno);
      elf_uninitialize();
    }

  mm_update(&g_mmstep, "after mount");

  /* Does the system support the PATH variable?  Has the PATH variable
   * already been set?  If YES and NO, then set the PATH variable to
   * the ROMFS mountpoint.
   */

#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
  (void)setenv("PATH", MOUNTPT, 1);
#endif

  /* Make sure that we are using our symbol take */

  exec_setsymtab(exports, nexports);

  /*************************************************************************
   * Case 1: Simple program with arguments
   *************************************************************************/

  /* Output a seperated so that we can clearly discriminate the output of
   * this program from the others.
   */

  testheader(g_hello);

  /* Initialize the attributes file actions structure */

  ret = posix_spawn_file_actions_init(&file_actions);
  if (ret != 0)
    {
      err("ERROR: posix_spawn_file_actions_init failed: %d\n", ret);
    }
  posix_spawn_file_actions_dump(&file_actions);

  ret = posix_spawnattr_init(&attr);
  if (ret != 0)
    {
      err("ERROR: posix_spawnattr_init failed: %d\n", ret);
    }
  posix_spawnattr_dump(&attr);

  mm_update(&g_mmstep, "after file_action/attr init");

  /* If the binary loader does not support the PATH variable, then
   * create the full path to the executable program.  Otherwise,
   * use the relative path so that the binary loader will have to
   * search the PATH variable to find the executable.
   */

#ifdef CONFIG_BINFMT_EXEPATH
  filepath = g_hello;
#else
  snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello);
  filepath = fullpath;
#endif

  /* Execute the program */

  mm_update(&g_mmstep, "before posix_spawn");

  ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, (FAR char * const*)&g_argv);
  if (ret != 0)
    {
      err("ERROR: posix_spawn failed: %d\n", ret);
    }

  sleep(4);
  mm_update(&g_mmstep, "after posix_spawn");

  /* Free attibutes and file actions */

  ret = posix_spawn_file_actions_destroy(&file_actions);
  if (ret != 0)
    {
      err("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret);
    }
  posix_spawn_file_actions_dump(&file_actions);

  ret = posix_spawnattr_destroy(&attr);
  if (ret != 0)
    {
      err("ERROR: posix_spawnattr_destroy failed: %d\n", ret);
    }
  posix_spawnattr_dump(&attr);

  mm_update(&g_mmstep, "after file_action/attr destruction");

  /*************************************************************************
   * Case 2: Simple program with redirection of stdin to a file input
   *************************************************************************/

  /* Output a seperated so that we can clearly discriminate the output of
   * this program from the others.
   */

  testheader(g_redirect);

  /* Initialize the attributes file actions structure */

  ret = posix_spawn_file_actions_init(&file_actions);
  if (ret != 0)
    {
      err("ERROR: posix_spawn_file_actions_init failed: %d\n", ret);
    }
  posix_spawn_file_actions_dump(&file_actions);

  ret = posix_spawnattr_init(&attr);
  if (ret != 0)
    {
      err("ERROR: posix_spawnattr_init failed: %d\n", ret);
    }
  posix_spawnattr_dump(&attr);

  mm_update(&g_mmstep, "after file_action/attr init");

  /* Set up to close stdin (0) and open testdata.txt as the program input */

  ret = posix_spawn_file_actions_addclose(&file_actions, 0);
  if (ret != 0)
    {
      err("ERROR: posix_spawn_file_actions_addclose failed: %d\n", ret);
    }
  posix_spawn_file_actions_dump(&file_actions);

  snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_data);
  ret = posix_spawn_file_actions_addopen(&file_actions, 0, fullpath, O_RDONLY, 0644);
  if (ret != 0)
    {
      err("ERROR: posix_spawn_file_actions_addopen failed: %d\n", ret);
    }
  posix_spawn_file_actions_dump(&file_actions);
  
  mm_update(&g_mmstep, "after adding file_actions");

  /* If the binary loader does not support the PATH variable, then
   * create the full path to the executable program.  Otherwise,
   * use the relative path so that the binary loader will have to
   * search the PATH variable to find the executable.
   */

#ifdef CONFIG_BINFMT_EXEPATH
  filepath = g_redirect;
#else
  snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect);
  filepath = fullpath;
#endif

  /* Execute the program */

  mm_update(&g_mmstep, "before posix_spawn");

  ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, NULL);
  if (ret != 0)
    {
      err("ERROR: posix_spawn failed: %d\n", ret);
    }

  sleep(2);
  mm_update(&g_mmstep, "after posix_spawn");

  /* Free attibutes and file actions */

  ret = posix_spawn_file_actions_destroy(&file_actions);
  if (ret != 0)
    {
      err("ERROR: posix_spawn_file_actions_destroy failed: %d\n", ret);
    }
  posix_spawn_file_actions_dump(&file_actions);

  ret = posix_spawnattr_destroy(&attr);
  if (ret != 0)
    {
      err("ERROR: posix_spawnattr_destroy failed: %d\n", ret);
    }
  posix_spawnattr_dump(&attr);

  mm_update(&g_mmstep, "after file_action/attr destruction");

  /* Clean-up */

  elf_uninitialize();

  mm_update(&g_mmstep, "End-of-Test");
  return 0;
}