<commit_before>#include <stdio.h>
#include "pthread.h"
#include "atomic.hh"
#include "mtrace.h"
#include "fstest.h"

static bool verbose = false;

static std::atomic<int> waiters;
static std::atomic<int> ready;

static void*
callthread(void* arg)
{
  int (*callf)(void) = (int (*)(void)) arg;

  waiters++;
  while (ready.load() == 0)
    ;

  callf();

  waiters--;
  while (ready.load() == 1)
    ;

  return 0;
}

int
main(int ac, char** av)
{
  setaffinity(0);

  for (int i = 0; fstests[i].setup; i++) {
    fstests[i].setup();
    int ra0 = fstests[i].call0();
    int ra1 = fstests[i].call1();
    fstests[i].cleanup();

    fstests[i].setup();
    int rb1 = fstests[i].call1();
    int rb0 = fstests[i].call0();
    fstests[i].cleanup();

    if (ra0 == rb0 && ra1 == rb1) {
      if (verbose)
        printf("test %d: commutes: %s->%d %s->%d\n",
               i, fstests[i].call0name, ra0, fstests[i].call1name, ra1);
    } else {
      printf("test %d: diverges: %s->%d %s->%d vs %s->%d %s->%d\n",
             i, fstests[i].call0name, ra0, fstests[i].call1name, ra1,
                fstests[i].call0name, rb0, fstests[i].call1name, rb1);
      continue;
    }
<commit_msg>fstest: allow specifying max # tests to run<commit_after>#include <stdio.h>
#include "pthread.h"
#include "atomic.hh"
#include "mtrace.h"
#include "fstest.h"

static bool verbose = false;

static std::atomic<int> waiters;
static std::atomic<int> ready;

static void*
callthread(void* arg)
{
  int (*callf)(void) = (int (*)(void)) arg;

  waiters++;
  while (ready.load() == 0)
    ;

  callf();

  waiters--;
  while (ready.load() == 1)
    ;

  return 0;
}

int
main(int ac, char** av)
{
  setaffinity(0);

  int max = 0;
  if (ac > 1)
    max = atoi(av[1]);

  for (int i = 0; (max == 0 || i < max) && fstests[i].setup; i++) {
    fstests[i].setup();
    int ra0 = fstests[i].call0();
    int ra1 = fstests[i].call1();
    fstests[i].cleanup();

    fstests[i].setup();
    int rb1 = fstests[i].call1();
    int rb0 = fstests[i].call0();
    fstests[i].cleanup();

    if (ra0 == rb0 && ra1 == rb1) {
      if (verbose)
        printf("test %d: commutes: %s->%d %s->%d\n",
               i, fstests[i].call0name, ra0, fstests[i].call1name, ra1);
    } else {
      printf("test %d: diverges: %s->%d %s->%d vs %s->%d %s->%d\n",
             i, fstests[i].call0name, ra0, fstests[i].call1name, ra1,
                fstests[i].call0name, rb0, fstests[i].call1name, rb1);
      continue;
    }

{'fraction_non_alphanumeric': 0.20436187399030695, 'fraction_numerical': 0.025040387722132473, 'mean_word_length': 2.787461773700306, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7339000', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1024, 'n_words': 226}