LCOV - code coverage report
Current view: top level - lib/tdb/test - run-mutex-allrecord-bench.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 22 29 75.9 %
Date: 2024-05-31 13:13:24 Functions: 3 4 75.0 %

          Line data    Source code
       1             : #include "../common/tdb_private.h"
       2             : #include "../common/io.c"
       3             : #include "../common/tdb.c"
       4             : #include "../common/lock.c"
       5             : #include "../common/freelist.c"
       6             : #include "../common/traverse.c"
       7             : #include "../common/transaction.c"
       8             : #include "../common/error.c"
       9             : #include "../common/open.c"
      10             : #include "../common/check.c"
      11             : #include "../common/hash.c"
      12             : #include "../common/mutex.c"
      13             : #include "tap-interface.h"
      14             : #include <stdlib.h>
      15             : #include <sys/types.h>
      16             : #include <sys/wait.h>
      17             : #include <stdarg.h>
      18             : 
      19             : static TDB_DATA key, data;
      20             : 
      21           0 : static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level,
      22             :                    const char *fmt, ...)
      23             : {
      24             :         va_list ap;
      25           0 :         va_start(ap, fmt);
      26           0 :         vfprintf(stderr, fmt, ap);
      27           0 :         va_end(ap);
      28           0 : }
      29             : 
      30           1 : static double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2)
      31             : {
      32           2 :         return (tv2->tv_sec - tv1->tv_sec) +
      33           1 :                (tv2->tv_usec - tv1->tv_usec)*1.0e-6;
      34             : }
      35             : 
      36           1 : static double timeval_elapsed(const struct timeval *tv)
      37             : {
      38             :         struct timeval tv2;
      39           1 :         gettimeofday(&tv2, NULL);
      40           1 :         return timeval_elapsed2(tv, &tv2);
      41             : }
      42             : 
      43             : /* The code should barf on TDBs created with rwlocks. */
      44           1 : int main(int argc, char *argv[])
      45             : {
      46             :         struct tdb_context *tdb;
      47             :         unsigned int log_count;
      48           1 :         struct tdb_logging_context log_ctx = { log_fn, &log_count };
      49             :         int ret;
      50             :         struct timeval start;
      51             :         double elapsed;
      52             :         bool runtime_support;
      53             : 
      54           1 :         runtime_support = tdb_runtime_check_for_robust_mutexes();
      55             : 
      56           1 :         if (!runtime_support) {
      57           0 :                 skip(1, "No robust mutex support");
      58           0 :                 return exit_status();
      59             :         }
      60             : 
      61           1 :         key.dsize = strlen("hi");
      62           1 :         key.dptr = discard_const_p(uint8_t, "hi");
      63           1 :         data.dsize = strlen("world");
      64           1 :         data.dptr = discard_const_p(uint8_t, "world");
      65             : 
      66           1 :         tdb = tdb_open_ex("mutex-allrecord-bench.tdb", 1000000,
      67             :                           TDB_INCOMPATIBLE_HASH|
      68             :                           TDB_MUTEX_LOCKING|
      69             :                           TDB_CLEAR_IF_FIRST,
      70             :                           O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
      71           1 :         ok(tdb, "tdb_open_ex should succeed");
      72             : 
      73           1 :         gettimeofday(&start, NULL);
      74           1 :         ret = tdb_allrecord_lock(tdb, F_WRLCK, TDB_LOCK_WAIT, false);
      75           1 :         elapsed = timeval_elapsed(&start);
      76             : 
      77           1 :         ok(ret == 0, "tdb_allrecord_lock should succeed");
      78             : 
      79           1 :         diag("allrecord_lock took %f seconds", elapsed);
      80             : 
      81           1 :         return exit_status();
      82             : }

Generated by: LCOV version 1.14