Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

fl_config.in

Blame
  • parallel-merge.c 3.45 KiB
    /* Generates about 1 MB of random data that is then divided into
       16 chunks.  A separate subprocess sorts each chunk; the
       subprocesses run in parallel.  Then we merge the chunks and
       verify that the result is what it should be. */
    
    #include "tests/vm/parallel-merge.h"
    #include <stdio.h>
    #include <syscall.h>
    #include "tests/arc4.h"
    #include "tests/lib.h"
    #include "tests/main.h"
    
    #define CHUNK_SIZE (128 * 1024)
    #define CHUNK_CNT 8                             /* Number of chunks. */
    #define DATA_SIZE (CHUNK_CNT * CHUNK_SIZE)      /* Buffer size. */
    
    unsigned char buf1[DATA_SIZE], buf2[DATA_SIZE];
    size_t histogram[256];
    
    /* Initialize buf1 with random data,
       then count the number of instances of each value within it. */
    static void
    init (void) 
    {
      struct arc4 arc4;
      size_t i;
    
      msg ("init");
    
      arc4_init (&arc4, "foobar", 6);
      arc4_crypt (&arc4, buf1, sizeof buf1);
      for (i = 0; i < sizeof buf1; i++)
        histogram[buf1[i]]++;
    }
    
    /* Sort each chunk of buf1 using SUBPROCESS,
       which is expected to return EXIT_STATUS. */
    static void
    sort_chunks (const char *subprocess, int exit_status)
    {
      pid_t children[CHUNK_CNT];
      size_t i;
    
      for (i = 0; i < CHUNK_CNT; i++) 
        {
          char fn[128];
          char cmd[128];
          int handle;
    
          msg ("sort chunk %zu", i);
    
          /* Write this chunk to a file. */
          snprintf (fn, sizeof fn, "buf%zu", i);
          create (fn, CHUNK_SIZE);
          quiet = true;
          CHECK ((handle = open (fn)) > 1, "open \"%s\"", fn);
          write (handle, buf1 + CHUNK_SIZE * i, CHUNK_SIZE);
          close (handle);
    
          /* Sort with subprocess. */
          snprintf (cmd, sizeof cmd, "%s %s", subprocess, fn);
          CHECK ((children[i] = exec (cmd)) != -1, "exec \"%s\"", cmd);
          quiet = false;
        }
    
      for (i = 0; i < CHUNK_CNT; i++) 
        {
          char fn[128];
          int handle;