Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/build/ltmain.sh  view on Meta::CPAN

        ;;
      /*)
        # Absolute path, do nothing.
        ;;
      *)
        # Relative path, prepend $cwd.
        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath
        ;;
    esac

    # Cancel out all the simple stuff to save iterations.  We also want
    # the path to end with a slash for ease of parsing, so make sure
    # there is one (and only one) here.
    func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \
          -e "$_G_removedotparts" -e "$_G_collapseslashes" -e "$_G_finalslash"`
    while :; do
      # Processed it all yet?
      if test / = "$func_normal_abspath_tpath"; then
        # If we ascended to the root using ".." the result may be empty now.
        if test -z "$func_normal_abspath_result"; then
          func_normal_abspath_result=/

src/subversion/subversion/libsvn_client/copy.c  view on Meta::CPAN

  first_src = first->src_abspath_or_url;
  src_is_url = svn_path_is_url(first_src);
  top_src = apr_pstrdup(subpool, first_src);
  for (i = 1; i < copy_pairs->nelts; i++)
    {
      /* We don't need to clear the subpool here for several reasons:
         1)  If we do, we can't use it to allocate the initial versions of
             top_src and top_dst (above).
         2)  We don't return any errors in the following loop, so we
             are guanteed to destroy the subpool at the end of this function.
         3)  The number of iterations is likely to be few, and the loop will
             be through quickly, so memory leakage will not be significant,
             in time or space.
      */
      const svn_client__copy_pair_t *pair =
        APR_ARRAY_IDX(copy_pairs, i, svn_client__copy_pair_t *);

      top_src = src_is_url
        ? svn_uri_get_longest_ancestor(top_src, pair->src_abspath_or_url,
                                       subpool)
        : svn_dirent_get_longest_ancestor(top_src, pair->src_abspath_or_url,

src/subversion/subversion/libsvn_client/merge.c  view on Meta::CPAN

                               merge_cmd_baton_t *merge_b,
                               apr_pool_t *scratch_pool)
{
  int i;
  svn_boolean_t is_rollback = (merged_range->start > merged_range->end);
  svn_boolean_t operative_merge;

  /* Update the WC mergeinfo here to account for our new
     merges, minus any unresolved conflicts and skips. */

  /* We need a scratch pool for iterations below. */
  apr_pool_t *iterpool = svn_pool_create(scratch_pool);

  svn_merge_range_t range = *merged_range;

  assert(! merge_b->dry_run);

  /* Regardless of what subtrees in MERGE_B->target->abspath might be missing
     could this merge have been operative? */
  operative_merge = subtree_touched_by_merge(merge_b->target->abspath,
                                             merge_b, iterpool);

src/subversion/subversion/libsvn_fs_base/reps-strings.c  view on Meta::CPAN


/*** Reading the contents from a representation. ***/

struct compose_handler_baton
{
  /* The combined window, and the pool it's allocated from. */
  svn_txdelta_window_t *window;
  apr_pool_t *window_pool;

  /* If the incoming window was self-compressed, and the combined WINDOW
     exists from previous iterations, SOURCE_BUF will point to the
     expanded self-compressed window. */
  char *source_buf;

  /* The trail for this operation. WINDOW_POOL will be a child of
     TRAIL->pool. No allocations will be made from TRAIL->pool itself. */
  trail_t *trail;

  /* TRUE when no more windows have to be read/combined. */
  svn_boolean_t done;

src/subversion/subversion/libsvn_fs_fs/fs_fs.c  view on Meta::CPAN

 ** EIO, ENOENT
 *
 * Some client implementations (at least the 2.6.18.5 kernel that ships
 * with Ubuntu Dapper) sometimes give spurious ENOENT (only on open) or
 * even EIO errors when trying to read these files that have been renamed
 * over on some other host.
 *
 ** Solution
 *
 * Try open and read of such files in try_stringbuf_from_file().  Call
 * this function within a loop of RECOVERABLE_RETRY_COUNT iterations
 * (though, realistically, the second try will succeed).
 */

#define RECOVERABLE_RETRY_COUNT 10

/* Read the file at PATH and return its content in *CONTENT. *CONTENT will
 * not be modified unless the whole file was read successfully.
 *
 * ESTALE, EIO and ENOENT will not cause this function to return an error
 * unless LAST_ATTEMPT has been set.  If MISSING is not NULL, indicate

src/subversion/subversion/libsvn_fs_fs/fs_fs.c  view on Meta::CPAN

      /* Check whether the length of the deltification chain is acceptable.
       * Otherwise, shared reps may form a non-skipping delta chain in
       * extreme cases. */
      apr_pool_t *sub_pool = svn_pool_create(pool);
      representation_t base_rep = **rep;

      /* Some reasonable limit, depending on how acceptable longer linear
       * chains are in this repo.  Also, allow for some minimal chain. */
      int max_chain_length = 2 * (int)ffd->max_linear_deltification + 2;

      /* re-use open files between iterations */
      svn_revnum_t rev_hint = SVN_INVALID_REVNUM;
      apr_file_t *file_hint = NULL;

      /* follow the delta chain towards the end but for at most
       * MAX_CHAIN_LENGTH steps. */
      for (; max_chain_length; --max_chain_length)
        {
          struct rep_state *rep_state;
          struct rep_args *rep_args;

src/subversion/subversion/libsvn_fs_fs/fs_fs.c  view on Meta::CPAN

  if (! SVN_IS_VALID_REVNUM(end))
    end = youngest;
  SVN_ERR(ensure_revision_exists(fs, start, pool));
  SVN_ERR(ensure_revision_exists(fs, end, pool));

  /* rep-cache verification. */
  SVN_ERR(svn_fs_fs__exists_rep_cache(&exists, fs, pool));
  if (exists)
    {
      /* provide a baton to allow the reuse of open file handles between
         iterations (saves 2/3 of OS level file operations). */
      verify_walker_baton_t *baton = apr_pcalloc(pool, sizeof(*baton));
      baton->rev_hint = SVN_INVALID_REVNUM;
      baton->pool = svn_pool_create(pool);
      baton->last_notified_revision = SVN_INVALID_REVNUM;
      baton->notify_func = notify_func;
      baton->notify_baton = notify_baton;

      /* tell the user that we are now ready to do *something* */
      if (notify_func)
        notify_func(SVN_INVALID_REVNUM, notify_baton, baton->pool);

src/subversion/subversion/libsvn_fs_fs/rep-cache.c  view on Meta::CPAN

                                                     svn_fs_t *,
                                                     apr_pool_t *),
                              void *walker_baton,
                              svn_cancel_func_t cancel_func,
                              void *cancel_baton,
                              apr_pool_t *pool)
{
  fs_fs_data_t *ffd = fs->fsap_data;
  svn_sqlite__stmt_t *stmt;
  svn_boolean_t have_row;
  int iterations = 0;

  apr_pool_t *iterpool = svn_pool_create(pool);

  /* Don't check ffd->rep_sharing_allowed. */
  SVN_ERR_ASSERT(ffd->format >= SVN_FS_FS__MIN_REP_SHARING_FORMAT);

  if (! ffd->rep_cache_db)
    SVN_ERR(svn_fs_fs__open_rep_cache(fs, pool));

  /* Check global invariants. */

src/subversion/subversion/libsvn_fs_fs/rep-cache.c  view on Meta::CPAN


  /* Walk the cache entries. */
  SVN_ERR(svn_sqlite__step(&have_row, stmt));
  while (have_row)
    {
      representation_t *rep;
      const char *sha1_digest;
      svn_error_t *err;

      /* Clear ITERPOOL occasionally. */
      if (iterations++ % 16 == 0)
        svn_pool_clear(iterpool);

      /* Check for cancellation. */
      if (cancel_func)
        {
          err = cancel_func(cancel_baton);
          if (err)
            return svn_error_compose_create(err, svn_sqlite__reset(stmt));
        }

src/subversion/subversion/libsvn_fs_fs/tree.c  view on Meta::CPAN

      && (result->path_len == path_len)
      && !memcmp(result->path, path, path_len))
    {
      return result;
    }

  /* need to do a full lookup.  Calculate the hash value
     (HASH_VALUE has been initialized to REVISION). */
  i = 0;
#if SVN_UNALIGNED_ACCESS_IS_OK
  /* We relax the dependency chain between iterations by processing
     two chunks from the input per hash_value self-multiplication.
     The HASH_VALUE update latency is now 1 MUL latency + 1 ADD latency
     per 2 chunks instead of 1 chunk.
   */
  for (; i + 8 <= path_len; i += 8)
    hash_value = hash_value * factor * factor
               + (  *(const apr_uint32_t*)(path + i) * factor
                  + *(const apr_uint32_t*)(path + i + 4));
#endif

src/subversion/subversion/libsvn_ra/compat.c  view on Meta::CPAN

  apr_hash_t *locations;

  /* A pool from which to allocate stuff stored in this baton. */
  apr_pool_t *pool;
};


/* Implements svn_log_entry_receiver_t; helper for slow_get_locations.
   As input, takes log_receiver_baton (defined above) and attempts to
   "fill in" locations in the baton over the course of many
   iterations. */
static svn_error_t *
log_receiver(void *baton,
             svn_log_entry_t *log_entry,
             apr_pool_t *pool)
{
  struct log_receiver_baton *lrb = baton;
  apr_pool_t *hash_pool = apr_hash_pool_get(lrb->locations);
  const char *current_path = lrb->last_path;
  const char *prev_path;

src/subversion/subversion/libsvn_ra_serf/property.c  view on Meta::CPAN


  iterpool = svn_pool_create(scratch_pool);
  for (ns_hi = apr_hash_first(scratch_pool, props); ns_hi;
       ns_hi = apr_hash_next(ns_hi))
    {
      void *ns_val;
      const void *ns_name;
      apr_hash_index_t *name_hi;

      /* NOTE: We do not clear ITERPOOL in this loop. Generally, there are
           very few namespaces, so this loop will not have many iterations.
           Instead, ITERPOOL is used for the inner loop.  */

      apr_hash_this(ns_hi, &ns_name, NULL, &ns_val);

      for (name_hi = apr_hash_first(scratch_pool, ns_val); name_hi;
           name_hi = apr_hash_next(name_hi))
        {
          void *prop_val;
          const void *prop_name;

src/subversion/subversion/libsvn_subr/config_file.c  view on Meta::CPAN

    }
  while (*c == '\r');

  return SVN_NO_ERROR;
}

/* Simplified version of parser_getc() to be used inside skipping loops.
 * It will not check for 'ungotton' chars and may or may not ignore '\r'.
 *
 * In a 'while(cond) getc();' loop, the first iteration must call
 * parser_getc to handle all the special cases.  Later iterations should
 * use parser_getc_plain for maximum performance.
 */
static APR_INLINE svn_error_t *
parser_getc_plain(parse_context_t *ctx, int *c)
{
  if (ctx->buffer_pos < ctx->buffer_size)
    {
      *c = (unsigned char)ctx->parser_buffer[ctx->buffer_pos];
      ctx->buffer_pos++;

src/subversion/subversion/libsvn_subr/crypto.c  view on Meta::CPAN

#include <apr_crypto.h>
#endif /* SVN_HAVE_CRYPTO */

#include "svn_types.h"
#include "svn_checksum.h"

#include "svn_private_config.h"
#include "private/svn_atomic.h"


/* 1000 iterations is the recommended minimum, per RFC 2898, section 4.2.  */
#define NUM_ITERATIONS 1000


/* Size (in bytes) of the random data we'll prepend to encrypted data. */
#define RANDOM_PREFIX_LEN 4


/* A structure for containing Subversion's cryptography-related bits
   (so we can avoid passing around APR-isms outside this module). */
struct svn_crypto__ctx_t {

src/subversion/subversion/libsvn_subr/subst.c  view on Meta::CPAN

  svn_stringbuf_t *readbuf;

  /* Offset of the first non-read character in readbuf. */
  apr_size_t readbuf_off;

  /* Buffer to hold read data
     between svn_stream_read() and translate_chunk(). */
  char *buf;
#define SVN__TRANSLATION_BUF_SIZE (SVN__STREAM_CHUNK_SIZE + 1)

  /* Pool for callback iterations */
  apr_pool_t *iterpool;
};


/* Implements svn_read_fn_t. */
static svn_error_t *
translated_stream_read(void *baton,
                       char *buffer,
                       apr_size_t *len)
{

src/subversion/subversion/tests/libsvn_delta/random-test.c  view on Meta::CPAN

#define DEFAULT_PRINT_WINDOWS 0
#define SEEDS 50
#define MAXSEQ 100


/* Initialize parameters for the random tests. */
extern int test_argc;
extern const char **test_argv;

static void init_params(apr_uint32_t *seed,
                        apr_uint32_t *maxlen, int *iterations,
                        int *dump_files, int *print_windows,
                        const char **random_bytes,
                        apr_size_t *bytes_range,
                        apr_pool_t *pool)
{
  apr_getopt_t *opt;
  char optch;
  const char *opt_arg;
  apr_status_t status;

  *seed = (apr_uint32_t) apr_time_now();
  *maxlen = DEFAULT_MAXLEN;
  *iterations = DEFAULT_ITERATIONS;
  *dump_files = DEFAULT_DUMP_FILES;
  *print_windows = DEFAULT_PRINT_WINDOWS;
  *random_bytes = NULL;
  *bytes_range = 256;

  apr_getopt_init(&opt, pool, test_argc, test_argv);
  while (APR_SUCCESS
         == (status = apr_getopt(opt, "s:l:n:r:FW", &optch, &opt_arg)))
    {
      switch (optch)
        {
        case 's':
          *seed = (apr_uint32_t) atol(opt_arg);
          break;
        case 'l':
          *maxlen = atoi(opt_arg);
          break;
        case 'n':
          *iterations = atoi(opt_arg);
          break;
        case 'r':
          *random_bytes = opt_arg + 1;
          *bytes_range = strlen(*random_bytes);
          break;
        case 'F':
          *dump_files = !*dump_files;
          break;
        case 'W':
          *print_windows = !*print_windows;

src/subversion/subversion/tests/libsvn_delta/random-test.c  view on Meta::CPAN

}



/* Implements svn_test_driver_t. */
static svn_error_t *
random_test(apr_pool_t *pool)
{
  apr_uint32_t seed, maxlen;
  apr_size_t bytes_range;
  int i, iterations, dump_files, print_windows;
  const char *random_bytes;

  /* Initialize parameters and print out the seed in case we dump core
     or something. */
  init_params(&seed, &maxlen, &iterations, &dump_files, &print_windows,
              &random_bytes, &bytes_range, pool);

  for (i = 0; i < iterations; i++)
    {
      /* Generate source and target for the delta and its application.  */
      apr_uint32_t subseed_base = svn_test_rand(&seed);
      apr_file_t *source = generate_random_file(maxlen, subseed_base, &seed,
                                                random_bytes, bytes_range,
                                                dump_files, pool);
      apr_file_t *target = generate_random_file(maxlen, subseed_base, &seed,
                                                random_bytes, bytes_range,
                                                dump_files, pool);
      apr_file_t *source_copy = copy_tempfile(source, pool);

src/subversion/subversion/tests/libsvn_delta/random-test.c  view on Meta::CPAN




/* (Note: *LAST_SEED is an output parameter.) */
static svn_error_t *
do_random_combine_test(apr_pool_t *pool,
                       apr_uint32_t *last_seed)
{
  apr_uint32_t seed, maxlen;
  apr_size_t bytes_range;
  int i, iterations, dump_files, print_windows;
  const char *random_bytes;

  /* Initialize parameters and print out the seed in case we dump core
     or something. */
  init_params(&seed, &maxlen, &iterations, &dump_files, &print_windows,
              &random_bytes, &bytes_range, pool);

  for (i = 0; i < iterations; i++)
    {
      /* Generate source and target for the delta and its application.  */
      apr_uint32_t subseed_base = svn_test_rand((*last_seed = seed, &seed));
      apr_file_t *source = generate_random_file(maxlen, subseed_base, &seed,
                                                random_bytes, bytes_range,
                                                dump_files, pool);
      apr_file_t *middle = generate_random_file(maxlen, subseed_base, &seed,
                                                random_bytes, bytes_range,
                                                dump_files, pool);
      apr_file_t *target = generate_random_file(maxlen, subseed_base, &seed,

src/subversion/subversion/tests/libsvn_delta/range-index-test.h  view on Meta::CPAN

  if (src_cp > tgt_cp)
    printf("WARN: More source than target copies; inefficient combiner?\n");
}


static svn_error_t *
random_range_index_test(apr_pool_t *pool)
{
  apr_uint32_t seed, maxlen;
  apr_size_t bytes_range;
  int i, iterations, dump_files, print_windows;
  const char *random_bytes;
  range_index_t *ndx;
  int tgt_cp = 0, src_cp = 0;

  /* Initialize parameters and print out the seed in case we dump core
     or something. */
  init_params(&seed, &maxlen, &iterations, &dump_files, &print_windows,
              &random_bytes, &bytes_range, pool);

  /* ### This test is expected to fail randomly at the moment, so don't
     enable it by default. --xbc */

  ndx = create_range_index(pool);
  for (i = 1; i <= iterations; ++i)
    {
      apr_off_t offset = svn_test_rand(&seed) % 47;
      apr_off_t limit = offset + svn_test_rand(&seed) % 16 + 1;
      range_list_node_t *list, *r;
      apr_off_t ret;
      const char *msg2;

      printf("%3d: Inserting [%3"APR_OFF_T_FMT",%3"APR_OFF_T_FMT") ...",
             i, offset, limit);
      splay_range_index(offset, ndx);

src/subversion/subversion/tests/libsvn_delta/range-index-test.h  view on Meta::CPAN

      else
        {
          printf(" Ooops!\n");
          print_range_index(ndx->tree, msg2, ret);
          check_copy_count(src_cp, tgt_cp);
          return svn_error_create(SVN_ERR_TEST_FAILED, NULL, "insert_range");
        }
    }

  printf("Final tree state:\n");
  print_range_index(ndx->tree, "", iterations + 1);
  check_copy_count(src_cp, tgt_cp);
  return SVN_NO_ERROR;
}


#endif /* SVN_RANGE_INDEX_TEST_H */

src/subversion/subversion/tests/libsvn_subr/named_atomic-test-common.h  view on Meta::CPAN

const char *name_namespace2 = NULL;

/* data structure containing all information we need to check for
 * a) passing some deadline
 * b) reaching the maximum iteration number
 */
typedef struct watchdog_t
{
  apr_time_t deadline;
  svn_named_atomic__t *atomic_counter;
  int iterations;
  int call_count; /* don't call apr_time_now() too often '*/
} watchdog_t;

/* init the WATCHDOG data structure for checking ATOMIC_COUNTER to reach
 * ITERATIONS and for the system time to pass a deadline MAX_DURATION
 * microsecs in the future.
 */
static void
init_watchdog(watchdog_t *watchdog,
              svn_named_atomic__t *atomic_counter,
              int iterations,
              apr_time_t max_duration)
{
  watchdog->deadline = apr_time_now() + max_duration;
  watchdog->atomic_counter = atomic_counter;
  watchdog->iterations = iterations;
  watchdog->call_count = 0;
}

/* test for watchdog conditions */
static svn_error_t *
check_watchdog(watchdog_t *watchdog, svn_boolean_t *done)
{
  apr_int64_t counter = 0;

  /* check for normal end of loop.
   * We are a watchdog, so don't check for errors. */
  *done = FALSE;
  svn_error_clear(svn_named_atomic__read(&counter,
                                         watchdog->atomic_counter));
  if (counter >= watchdog->iterations)
    {
      *done = TRUE;
      return SVN_NO_ERROR;
    }

  /* Check the system time and indicate when deadline has passed */
  if (++watchdog->call_count > 100)
    {
      watchdog->call_count = 100;
      if (apr_time_now() > watchdog->deadline)
        return svn_error_createf(SVN_ERR_TEST_FAILED,
                                0,
                                "Deadline has passed at iteration %d/%d",
                                (int)counter, watchdog->iterations);
    }

  /* no problem so far */
  return SVN_NO_ERROR;
}

/* "pipeline" test: initialization code executed by the worker with ID 0.
 * Pushes COUNT tokens into ATOMIC_OUT and checks for ATOMIC_COUNTER not to
 * exceed ITERATIONS (early termination).
 */

src/subversion/subversion/tests/libsvn_subr/named_atomic-test-common.h  view on Meta::CPAN


/* "pipeline" test: the main loop. Each one of the COUNT workers receives
 * data in its ATOMIC_IN and passes it on to ATOMIC_OUT until ATOMIC_COUNTER
 * exceeds ITERATIONS.
 */
static svn_error_t *
test_pipeline_loop(svn_named_atomic__t *atomic_in,
                   svn_named_atomic__t *atomic_out,
                   svn_named_atomic__t *atomic_counter,
                   int count,
                   int iterations,
                   watchdog_t *watchdog)
{
  apr_int64_t value = 0, old_value, last_value = 0;
  apr_int64_t counter;
  svn_boolean_t done = FALSE;

  /* Pass the tokens along */

  do
    {

src/subversion/subversion/tests/libsvn_subr/named_atomic-test-common.h  view on Meta::CPAN

                                            0,
                                            atomic_out));
          SVN_ERR(check_watchdog(watchdog, &done));
          if (done) return SVN_NO_ERROR;
        }
      while (old_value != 0);

      /* Count the number of operations */
      SVN_ERR(svn_named_atomic__add(&counter, 1, atomic_counter));
    }
   while (counter < iterations);

   /* done */

   return SVN_NO_ERROR;
}

/* "pipeline" test: worker with ID 0 initializes the data; all workers
 * (COUNT in total) have one input and one output bucket that form a ring
 * spanning all workers. Each worker passes the value along ITERATIONS times.
 */
static svn_error_t *
test_pipeline(int id, int count, int iterations, apr_pool_t *pool)
{
  svn_atomic_namespace__t *ns;
  svn_named_atomic__t *atomic_in;
  svn_named_atomic__t *atomic_out;
  svn_named_atomic__t *atomic_counter;
  svn_error_t *err = SVN_NO_ERROR;
  watchdog_t watchdog;

  /* get the two I/O atomics for this thread */
  SVN_ERR(svn_atomic_namespace__create(&ns, name_namespace, pool));

src/subversion/subversion/tests/libsvn_subr/named_atomic-test-common.h  view on Meta::CPAN

                                            ATOMIC_NAME,
                                            apr_itoa(pool,
                                                     (id + 1) % count),
                                            NULL),
                                FALSE));

  /* our iteration counter */
  SVN_ERR(svn_named_atomic__get(&atomic_counter, ns, "counter", FALSE));

  /* safeguard our execution time. Limit it to 20s */
  init_watchdog(&watchdog, atomic_counter, iterations, 20000000);

  /* fill pipeline */
  if (id == 0)
    err = test_pipeline_prepare(atomic_out, count, &watchdog);

   /* Pass the tokens along */
   if (!err)
     err = test_pipeline_loop(atomic_in, atomic_out, atomic_counter,
                              count, iterations, &watchdog);

   /* if we experienced an error, cause everybody to exit */
   if (err)
     svn_error_clear(svn_named_atomic__write(NULL, iterations, atomic_counter));

   /* done */

   return err;
}

src/subversion/subversion/tests/libsvn_subr/named_atomic-test-proc.c  view on Meta::CPAN

/* Very simple process frame around the actual test code */
int
main(int argc, const char *argv[])
{
  svn_boolean_t got_error = FALSE;
  apr_pool_t *pool;
  svn_error_t *err;

  int id = 0;
  int count = 0;
  int iterations = 0;

  /* Initialize APR (Apache pools) */
  if (apr_initialize() != APR_SUCCESS)
    {
      printf("apr_initialize() failed.\n");
      exit(1);
    }

  pool = svn_pool_create(NULL);

src/subversion/subversion/tests/libsvn_subr/named_atomic-test-proc.c  view on Meta::CPAN

    {
      if (argc == 1) /* used to test that this executable can be started */
        exit(0);

      printf("Usage: named_atomic-proc-test ID COUNT ITERATIONS NS.\n");
      exit(1);
    }

  id = (int)apr_atoi64(argv[1]);
  count = (int)apr_atoi64(argv[2]);
  iterations = (int)apr_atoi64(argv[3]);
  name_namespace = argv[4];

  /* run test routine */

  err = test_pipeline(id, count, iterations, pool);
  if (err)
  {
    const char *prefix = apr_psprintf(pool, "Process %d: ", id);
    got_error = TRUE;
    svn_handle_error2(err, stdout, FALSE, prefix);
    svn_error_clear(err);
  }

  /* Clean up APR */
  svn_pool_destroy(pool);

src/subversion/subversion/tests/libsvn_subr/named_atomic-test.c  view on Meta::CPAN

/* shared test implementation */
#include "named_atomic-test-common.h"

/* Name of the worker process executable */
#define TEST_PROC "named_atomic-proc-test"

/* number of hardware threads (logical cores) that we may use.
 * Will be set to at least 2 - even on unicore machines. */
static int hw_thread_count = 0;

/* number of iterations that we should perform on concurrency tests
 * (will be calibrated to about 1s runtime)*/
static int suggested_iterations = 0;

/* If possible, translate PROC to a global path and set DIRECTORY to
 * the current directory.
 */
static svn_error_t *
adjust_proc_path(const char **proc, const char **directory, apr_pool_t *pool)
{
#ifdef WIN32
  /* Under Windows, the test will not be in the current directory
   * and neither will be PROC. Therefore, determine its full path */

src/subversion/subversion/tests/libsvn_subr/named_atomic-test.c  view on Meta::CPAN

/* our thread function type
 */
typedef svn_error_t *(*thread_func_t)(int, int, int, apr_pool_t *);

/* Per-thread input and output data.
 */
struct thread_baton
{
  int thread_count;
  int thread_no;
  int iterations;
  svn_error_t *result;
  thread_func_t func;
};

/* APR thread function implementation: A wrapper around baton->func that
 * handles the svn_error_t return value.
 */
static void *
APR_THREAD_FUNC test_thread(apr_thread_t *thread, void *baton)
{
  struct thread_baton *params = baton;
  apr_pool_t *pool = svn_pool_create_ex(NULL, NULL);

  params->result = (*params->func)(params->thread_no,
                                   params->thread_count,
                                   params->iterations,
                                   pool);
  svn_pool_destroy(pool);
  apr_thread_exit(thread, APR_SUCCESS);

  return NULL;
}

/* Runs FUNC in COUNT concurrent threads ITERATION times and combines the
 * results.
 */
static svn_error_t *
run_threads(apr_pool_t *pool, int count, int iterations, thread_func_t func)
{
  apr_status_t status;
  int i;
  svn_error_t *error = SVN_NO_ERROR;

  /* all threads and their I/O data */
  apr_thread_t **threads = apr_palloc(pool, count * sizeof(*threads));
  struct thread_baton *batons = apr_palloc(pool, count * sizeof(*batons));

  /* start threads */
  for (i = 0; i < count; ++i)
    {
      batons[i].thread_count = count;
      batons[i].thread_no = i;
      batons[i].iterations = iterations;
      batons[i].func = func;

      status = apr_thread_create(&threads[i],
                                 NULL,
                                 test_thread,
                                 &batons[i],
                                 pool);
      if (status != APR_SUCCESS)
        SVN_ERR(svn_error_wrap_apr(status, "could not create a thread"));
    }

src/subversion/subversion/tests/libsvn_subr/named_atomic-test.c  view on Meta::CPAN

           (batons[i].result, apr_psprintf(pool, "Thread %d failed", i)));
    }

  return error;
}
#endif

/* Runs PROC in COUNT concurrent worker processes and check the results.
 */
static svn_error_t *
run_procs(apr_pool_t *pool, const char *proc, int count, int iterations)
{
  int i, k;
  svn_error_t *error = SVN_NO_ERROR;
  const char * directory = NULL;

  /* all processes and their I/O data */
  apr_proc_t *process = apr_palloc(pool, count * sizeof(*process));
  apr_file_t *common_stdout = NULL;
  apr_file_open_stdout(&common_stdout, pool);

  SVN_ERR(adjust_proc_path(&proc, &directory, pool));

  /* start sub-processes */
  for (i = 0; i < count; ++i)
    {
      const char * args[6];

      args[0] = proc;
      args[1] = apr_itoa(pool, i);
      args[2] = apr_itoa(pool, count);
      args[3] = apr_itoa(pool, iterations);
      args[4] = name_namespace;
      args[5] = NULL;

      error = svn_io_start_cmd3(&process[i],
                                directory,  /* working directory */
                                args[0],
                                args,
                                NULL,       /* environment */
                                FALSE,      /* no handle inheritance */
                                FALSE,      /* no STDIN pipe */

src/subversion/subversion/tests/libsvn_subr/named_atomic-test.c  view on Meta::CPAN


          return error;
        }
    }

  /* Wait for sub-processes to finish and return result. */
  for (i = 0; i < count; ++i)
    {
      const char *cmd = apr_psprintf(pool,
                                     "named_atomic-test-proc %d %d %d",
                                     i, count, iterations);
      error = svn_error_compose_create(error,
                                       svn_io_wait_for_cmd(&process[i],
                                                           cmd, NULL, NULL,
                                                           pool));
    }

  return error;
}

/* Set SUGGESTED_ITERATIONS to a value that COUNT workers will take
 * about 1 second to execute.
 */
static svn_error_t *
calibrate_iterations(apr_pool_t *pool, int count)
{
  apr_time_t start;
  int calib_iterations;
  double taken = 0.0;

  /* increase iterations until we pass the 100ms mark */

  for (calib_iterations = 10; taken < 100000.0; calib_iterations *= 2)
    {
      apr_pool_t *scratch = svn_pool_create(pool);
      SVN_ERR(init_concurrency_test_shm(scratch, count));

      start = apr_time_now();
      SVN_ERR(run_procs(pool, TEST_PROC, count, calib_iterations));

      taken = (double)(apr_time_now() - start);
      svn_pool_destroy(scratch);
    }

  /* scale that to 1s */

  suggested_iterations = (int)(1000000.0 / taken * calib_iterations);

  return SVN_NO_ERROR;
}

/* Find out how far the system will scale, i.e. how many workers can be
 * run concurrently without experiencing significant slowdowns.
 * Sets HW_THREAD_COUNT to a value of 2 .. 32 (limit the system impact in
 * case our heuristics fail) and determines the number of iterations.
 * Can be called multiple times but will skip the calculations after the
 * first successful run.
 */
static svn_error_t *
calibrate_concurrency(apr_pool_t *pool)
{
  if (hw_thread_count == 0)
    {
      /* these parameters should be ok even on very slow machines */
      hw_thread_count = 2;
      suggested_iterations = 100;

      /* if we've got a proper machine and OS setup, let's prepare for
       * some real testing */
      if (svn_named_atomic__is_efficient() && proc_found(TEST_PROC, pool))
        {
          SVN_ERR(calibrate_iterations(pool, 2));
          for (; hw_thread_count < 32; hw_thread_count *= 2)
            {
              int saved_suggestion = suggested_iterations;

              /* run with an additional core to spare
               * (even low CPU usage might cause heavy context switching) */
              SVN_ERR(calibrate_iterations(pool, hw_thread_count * 2 + 1));
              if (suggested_iterations < 100000)
                {
                  /* Machines with only a small number of cores are prone
                   * to inconsistent performance due context switching.
                   * Reduce the number of iterations on those machines. */
                  suggested_iterations = hw_thread_count > 2
                                       ? saved_suggestion
                                       : saved_suggestion / 2;
                  break;
                }
            }
        }

      printf("using %d cores for %d iterations\n", hw_thread_count,
                                                   suggested_iterations);
  }

  return SVN_NO_ERROR;
}

/* The individual tests */

static svn_error_t *
test_basics(apr_pool_t *pool)
{

src/subversion/subversion/tests/libsvn_subr/named_atomic-test.c  view on Meta::CPAN


static svn_error_t *
test_multithreaded(apr_pool_t *pool)
{
#if APR_HAS_THREADS
  SVN_ERR(init_test_shm(pool));

  SVN_ERR(calibrate_concurrency(pool));

  SVN_ERR(init_concurrency_test_shm(pool, hw_thread_count));
  SVN_ERR(run_threads(pool, hw_thread_count, suggested_iterations, test_pipeline));

  return SVN_NO_ERROR;
#else
  return svn_error_create(SVN_ERR_TEST_SKIPPED, NULL, NULL);
#endif
}

static svn_error_t *
test_multiprocess(apr_pool_t *pool)
{
  if (!proc_found(TEST_PROC, pool))
    return svn_error_wrap_apr(SVN_ERR_TEST_SKIPPED,
                              "executable '%s' not found", TEST_PROC);

  SVN_ERR(init_test_shm(pool));

  SVN_ERR(calibrate_concurrency(pool));

  SVN_ERR(init_concurrency_test_shm(pool, hw_thread_count));
  SVN_ERR(run_procs(pool, TEST_PROC, hw_thread_count, suggested_iterations));

  return SVN_NO_ERROR;
}

/*
   ====================================================================
   If you add a new test to this file, update this array.

   (These globals are required by our included main())
*/

src/subversion/subversion/tests/libsvn_subr/utf-test.c  view on Meta::CPAN

}

/* Compare the two different implementations using random data. */
static svn_error_t *
utf_validate2(apr_pool_t *pool)
{
  int i;

  seed_val();

  /* We want enough iterations so that most runs get both valid and invalid
     strings.  We also want enough iterations such that a deliberate error
     in one of the implementations will trigger a failure.  By experiment
     the second requirement requires a much larger number of iterations
     that the first. */
  for (i = 0; i < 100000; ++i)
    {
      unsigned int j;
      char str[64];
      apr_size_t len;

      /* A random string; experiment shows that it's occasionally (less
         than 1%) valid but usually invalid. */
      for (j = 0; j < sizeof(str) - 1; ++j)

src/subversion/tools/dev/fsfs-reorg.c  view on Meta::CPAN

        break;

      case noderev_fragment:
        node = fragment->data;
        node->target.offset = new_position;
        break;
    }
}

/* Move the fragments in PACK's target fragment list to their final offsets.
 * This may require several iterations if the fudge factors turned out to
 * be insufficient.  Use POOL for allocations.
 */
static svn_error_t *
pack_revisions(fs_fs_t *fs,
               revision_pack_t *pack,
               apr_pool_t *pool)
{
  int i;
  fragment_t *fragment, *next;
  svn_boolean_t needed_to_expand;



( run in 0.842 second using v1.01-cache-2.11-cpan-71847e10f99 )