Changeset 13909


Ignore:
Timestamp:
Jan 31, 2013, 5:39:06 PM (8 years ago)
Author:
jordan
Message:

(libT) add assertions to check that block-writing functions are only invoked in the libtransmission thread

Location:
trunk/libtransmission
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/cache.c

    r13868 r13909  
    2222#include "ptrarray.h"
    2323#include "torrent.h"
     24#include "trevent.h"
    2425#include "utils.h"
    2526
     
    333334{
    334335  struct cache_block * cb = findBlock (cache, torrent, piece, offset);
     336
     337  assert (tr_amInEventThread (torrent->session));
    335338
    336339  if (cb == NULL)
  • trunk/libtransmission/move-test.c

    r13882 r13909  
    1414#include "cache.h"
    1515#include "resume.h"
     16#include "trevent.h"
    1617#include "torrent.h" /* tr_isTorrent() */
    1718#include "utils.h" /* tr_mkdirp() */
     
    2324****
    2425***/
     26
     27#define verify_and_block_until_done(tor) \
     28  do { \
     29    do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
     30    tr_torrentVerify (tor); \
     31    do { tr_wait_msec (10); } while (tor->verifyState != TR_VERIFY_NONE); \
     32  } while (0)
    2533
    2634static void
     
    4250  } while (0)
    4351
     52struct test_incomplete_dir_is_subdir_of_download_dir_data
     53{
     54  tr_torrent * tor;
     55  tr_block_index_t block;
     56  tr_piece_index_t pieceIndex;
     57  uint32_t offset;
     58  struct evbuffer * buf;
     59  bool done;
     60};
     61
     62static void
     63test_incomplete_dir_is_subdir_of_download_dir_threadfunc (void * vdata)
     64{
     65  struct test_incomplete_dir_is_subdir_of_download_dir_data * data = vdata;
     66  tr_cacheWriteBlock (session->cache, data->tor, 0, data->offset, data->tor->blockSize, data->buf);
     67  tr_torrentGotBlock (data->tor, data->block);
     68  data->done = true;
     69}
     70 
     71
    4472static int
    4573test_incomplete_dir_is_subdir_of_download_dir (void)
    4674{
     75  size_t i;
    4776  char * incomplete_dir;
    4877  tr_torrent * tor;
     
    6695  check_int_eq (tor->info.pieceSize, tr_torrentStat(tor)->leftUntilDone);
    6796
     97  completeness = completeness_unset;
     98  tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness);
     99
    68100  /* now finish writing it */
    69101  {
    70     uint32_t offset;
    71     tr_block_index_t first, last, i;
    72     struct evbuffer * buf = evbuffer_new ();
     102    tr_block_index_t first, last;
    73103    char * zero_block = tr_new0 (char, tor->blockSize);
     104    struct test_incomplete_dir_is_subdir_of_download_dir_data data;
    74105
    75     completeness = completeness_unset;
    76     tr_torrentSetCompletenessCallback (tor, zeroes_completeness_func, &completeness);
     106    data.tor = tor;
     107    data.pieceIndex = 0;
     108    data.buf = evbuffer_new ();
    77109
    78     tr_torGetPieceBlockRange (tor, 0, &first, &last);
    79     for (offset=0, i=first; i<=last; ++i, offset+=tor->blockSize)
     110    tr_torGetPieceBlockRange (tor, data.pieceIndex, &first, &last);
     111    for (i=first; i<=last; ++i)
    80112      {
    81         evbuffer_add (buf, zero_block, tor->blockSize);
    82         tr_cacheWriteBlock (session->cache, tor, 0, offset, tor->blockSize, buf);
    83         tr_torrentGotBlock (tor, i);
     113        evbuffer_add (data.buf, zero_block, tor->blockSize);
     114        data.block = i;
     115        data.done = false;
     116        data.offset = data.block * tor->blockSize;
     117        tr_runInEventThread (session, test_incomplete_dir_is_subdir_of_download_dir_threadfunc, &data);
     118        do { tr_wait_msec(50); } while (!data.done);
    84119      }
    85     sync ();
    86120
    87     tr_torrentVerify (tor);
    88     while ((completeness==completeness_unset) && (time(NULL)<=deadline))
    89       tr_wait_msec (50);
    90     check_int_eq (TR_SEED, completeness);
    91     for (i=0; i<tor->info.fileCount; ++i)
    92       check_file_location (tor, i, tr_buildPath (downloadDir, tor->info.files[i].name, NULL));
    93 
    94     evbuffer_free (buf);
     121    evbuffer_free (data.buf);
    95122    tr_free (zero_block);
    96123  }
    97124
     125  verify_and_block_until_done (tor);
     126  check_int_eq (0, tr_torrentStat(tor)->leftUntilDone);
     127
     128  while ((completeness==completeness_unset) && (time(NULL)<=deadline))
     129    tr_wait_msec (50);
     130
     131  check_int_eq (TR_SEED, completeness);
     132  for (i=0; i<tor->info.fileCount; ++i)
     133    check_file_location (tor, i, tr_buildPath (downloadDir, tor->info.files[i].name, NULL));
    98134
    99135  /* cleanup */
  • trunk/libtransmission/torrent.c

    r13905 r13909  
    29512951            /* blow away the leftover subdirectories in the old location */
    29522952            if (do_move)
    2953                 tr_torrentDeleteLocalData (tor, remove);
     2953              tr_torrentDeleteLocalData (tor, remove);
    29542954
    29552955            /* set the new location and reverify */
     
    30663066{
    30673067  const bool block_is_new = !tr_cpBlockIsComplete (&tor->completion, block);
     3068
     3069  assert (tr_isTorrent (tor));
     3070  assert (tr_amInEventThread (tor->session));
    30683071
    30693072  if (block_is_new)
Note: See TracChangeset for help on using the changeset viewer.