<commit_before>/* Gearman server and library
 * Copyright (C) 2008 <NAME>, <NAME>
 * All rights reserved.
 *
 * Use and distribution licensed under the BSD license.  See
 * the COPYING file in the parent directory for full text.
 */

#include "config.h"

#if defined(NDEBUG)
# undef NDEBUG
#endif

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>

#include "test_gearmand.h"

#ifdef HAVE_LIBDRIZZLE
#include <libgearman-server/queue_libdrizzle.h>
#endif

#ifdef HAVE_LIBMEMCACHED
#include <libgearman-server/queue_libmemcached.h>
#endif

#ifdef HAVE_LIBSQLITE3
#include <libgearman-server/queue_libsqlite3.h>
#endif

pid_t test_gearmand_start(in_port_t port, const char *queue_type,
                          char *argv[], int argc)
{
  pid_t gearmand_pid;
  gearmand_st *gearmand;
  gearman_conf_st conf;

  assert((gearmand_pid= fork()) != -1);

  if (gearmand_pid == 0)
  {
    assert(gearman_conf_create(&conf) != NULL);
#ifdef HAVE_LIBDRIZZLE
    assert(gearman_server_queue_libdrizzle_conf(&conf) == GEARMAN_SUCCESS);
#endif
#ifdef HAVE_LIBMEMCACHED
    assert(gearman_server_queue_libmemcached_conf(&conf) == GEARMAN_SUCCESS);
#endif
#ifdef HAVE_LIBSQLITE3
    assert(gearman_server_queue_libsqlite3_conf(&conf) == GEARMAN_SUCCESS);
#endif

    assert(gearman_conf_parse_args(&conf, argc, argv) == GEARMAN_SUCCESS);

    gearmand= gearmand_create(NULL, port);
    assert(gearmand != NULL);

    if (queue_type != NULL)
    {
      assert(argc);
      assert(argv);
#ifdef HAVE_LIBDRIZZLE
      if (!strcmp(queue_type, "libdrizzle"))
        assert((gearmand_queue_libdrizzle_init(gearmand, &conf)) == GEARMAN_SUCCESS);
      else
#endif
#ifdef HAVE_LIBMEMCACHED
      if (!strcmp(queue_type, "libmemcached"))
        assert((gearmand_queue_libmemcached_init(gearmand, &conf)) == GEARMAN_SUCCESS);
      else
#endif
#ifdef HAVE_LIBSQLITE3
      if (!strcmp(queue_type, "libsqlite3"))
        assert((gearmand_queue_libsqlite3_init(gearmand, &conf)) == GEARMAN_SUCCESS);
      else
#endif
      {
        assert(1);
      }
    }

    assert(gearmand_run(gearmand) != GEARMAN_SUCCESS);

    if (queue_type != NULL)
    {
#ifdef HAVE_LIBDRIZZLE
      if (!strcmp(queue_type, "libdrizzle"))
        gearmand_queue_libdrizzle_deinit(gearmand);
#endif
#ifdef HAVE_LIBMEMCACHED
      if (!strcmp(queue_type, "libmemcached"))
        gearmand_queue_libmemcached_deinit(gearmand);
#endif
#ifdef HAVE_LIBSQLITE3
      if (!strcmp(queue_type, "libmemcached"))
        gearmand_queue_libsqlite3_deinit(gearmand);
#endif
    }

    gearmand_free(gearmand);
    exit(0);
  }
  else
  {
    /* Wait for the server to start and bind the port. */
    sleep(1);
  }

  return gearmand_pid;
}

void test_gearmand_stop(pid_t gearmand_pid)
{
  assert(kill(gearmand_pid, SIGKILL) == 0);
  assert(waitpid(gearmand_pid, NULL, 0) == gearmand_pid);
}
<commit_msg>Fix for assert (aka, not make it so that undef assert() will remove commands).<commit_after>/* Gearman server and library
 * Copyright (C) 2008 <NAME>, <NAME>
 * All rights reserved.
 *
 * Use and distribution licensed under the BSD license.  See
 * the COPYING file in the parent directory for full text.
 */

#include "config.h"

#if defined(NDEBUG)
# undef NDEBUG
#endif

#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "test_gearmand.h"

#ifdef HAVE_LIBDRIZZLE
#include <libgearman-server/queue_libdrizzle.h>
#endif

#ifdef HAVE_LIBMEMCACHED
#include <libgearman-server/queue_libmemcached.h>
#endif

#ifdef HAVE_LIBSQLITE3
#include <libgearman-server/queue_libsqlite3.h>
#endif

pid_t test_gearmand_start(in_port_t port, const char *queue_type,
                          char *argv[], int argc)
{
  pid_t gearmand_pid;
  gearmand_st *gearmand;
  gearman_conf_st conf;

  gearmand_pid= fork();
  assert(gearmand_pid != -1);

  if (gearmand_pid == 0)
  {
    gearman_conf_st *conf_ptr;
    gearman_return_t ret;

    conf_ptr= gearman_conf_create(&conf);
    assert(conf_ptr);
#ifdef HAVE_LIBDRIZZLE
    ret= gearman_server_queue_libdrizzle_conf(&conf);
    assert(ret == GEARMAN_SUCCESS);
#endif
#ifdef HAVE_LIBMEMCACHED
    ret= gearman_server_queue_libmemcached_conf(&conf);
    assert(ret == GEARMAN_SUCCESS);
#endif
#ifdef HAVE_LIBSQLITE3
    ret= gearman_server_queue_libsqlite3_conf(&conf);
    assert(ret == GEARMAN_SUCCESS);
#endif

    ret= gearman_conf_parse_args(&conf, argc, argv);
    assert(ret == GEARMAN_SUCCESS);

    gearmand= gearmand_create(NULL, port);
    assert(gearmand != NULL);

    if (queue_type != NULL)
    {
      assert(argc);
      assert(argv);
#ifdef HAVE_LIBDRIZZLE
      if (! strcmp(queue_type, "libdrizzle"))
      {
        ret= gearmand_queue_libdrizzle_init(gearmand, &conf);
        assert(ret == GEARMAN_SUCCESS);
      }
      else
#endif
#ifdef HAVE_LIBMEMCACHED
      if (! strcmp(queue_type, "libmemcached"))
      {
        ret= gearmand_queue_libmemcached_init(gearmand, &conf);
        assert(ret == GEARMAN_SUCCESS);
      }
      else
#endif
#ifdef HAVE_LIBSQLITE3
      if (! strcmp(queue_type, "libsqlite3"))
      {
        ret= gearmand_queue_libsqlite3_init(gearmand, &conf);
        assert(ret == GEARMAN_SUCCESS);
      }
      else
#endif
      {
        assert(1);
      }
    }

    ret= gearmand_run(gearmand);
    assert(ret != GEARMAN_SUCCESS);

    if (queue_type != NULL)
    {
#ifdef HAVE_LIBDRIZZLE
      if (!strcmp(queue_type, "libdrizzle"))
        gearmand_queue_libdrizzle_deinit(gearmand);
#endif
#ifdef HAVE_LIBMEMCACHED
      if (!strcmp(queue_type, "libmemcached"))
        gearmand_queue_libmemcached_deinit(gearmand);
#endif
#ifdef HAVE_LIBSQLITE3
      if (!strcmp(queue_type, "libmemcached"))
        gearmand_queue_libsqlite3_deinit(gearmand);
#endif
    }

    gearmand_free(gearmand);
    exit(0);
  }
  else
  {
    /* Wait for the server to start and bind the port. */
    sleep(1);
  }

  return gearmand_pid;
}

void test_gearmand_stop(pid_t gearmand_pid)
{
  int ret;
  pid_t pid;

  ret= kill(gearmand_pid, SIGKILL);
  
  if (ret != 0)
  {
    if (ret == -1)
    {
      perror(strerror(errno));
    }

    assert(ret == 0); // If assert is enabled, we assert(), otherwise we return
    return;
  }

  pid= waitpid(gearmand_pid, NULL, 0);
  assert(pid == gearmand_pid);
}

{'fraction_non_alphanumeric': 0.11786600496277916, 'fraction_numerical': 0.006513647642679901, 'mean_word_length': 3.819880418535127, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '621866', 'n_tokens_mistral': 2435, 'n_tokens_neox': 2391, 'n_words': 476}