LCOV - code coverage report
Current view: directory - tests/performance - perf_test_basics.cc (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 27 27 100.0 %
Date: 2014-06-18 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #include <setjmp.h>
       8                 : #include <sys/mman.h>
       9                 : 
      10                 : #if NACL_LINUX
      11                 : # include <sys/syscall.h>
      12                 : # include <time.h>
      13                 : #endif
      14                 : 
      15                 : #include "native_client/src/include/nacl_assert.h"
      16                 : #if defined(__native_client__)
      17                 : #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
      18                 : #endif
      19                 : #include "native_client/tests/performance/perf_test_compat_osx.h"
      20                 : #include "native_client/tests/performance/perf_test_runner.h"
      21                 : 
      22                 : 
      23                 : // This measures the overhead of the test framework and a virtual
      24                 : // function call.
      25               6 : class TestNull : public PerfTest {
      26                 :  public:
      27                 :   virtual void run() {
      28        91084221 :   }
      29                 : };
      30               1 : PERF_TEST_DECLARE(TestNull)
      31                 : 
      32                 : #if defined(__native_client__)
      33                 : class TestNaClSyscall : public PerfTest {
      34                 :  public:
      35                 :   virtual void run() {
      36                 :     NACL_SYSCALL(null)();
      37                 :   }
      38                 : };
      39                 : PERF_TEST_DECLARE(TestNaClSyscall)
      40                 : #endif
      41                 : 
      42                 : #if NACL_LINUX || NACL_OSX
      43               6 : class TestHostSyscall : public PerfTest {
      44                 :  public:
      45                 :   virtual void run() {
      46                 : #if NACL_LINUX
      47                 :     // Don't use getpid() here, because glibc caches the pid in userland.
      48                 :     int rc = syscall(__NR_getpid);
      49                 : #elif NACL_OSX
      50                 :     // Mac OS X's libsyscall caches the result of getpid, but not getppid.
      51         2679871 :     int rc = getppid();
      52                 : #endif
      53         8039613 :     ASSERT_GT(rc, 0);
      54         2679871 :   }
      55                 : };
      56               1 : PERF_TEST_DECLARE(TestHostSyscall)
      57                 : #endif
      58                 : 
      59                 : // Measure the speed of saving and restoring all callee-saved
      60                 : // registers, assuming the compiler does not optimize the setjmp() and
      61                 : // longjmp() calls away.  This is likely to be slower than TestNull
      62                 : // but faster than TestNaClSyscall.
      63               6 : class TestSetjmpLongjmp : public PerfTest {
      64                 :  public:
      65                 :   virtual void run() {
      66          880032 :     jmp_buf buf;
      67          880032 :     if (!setjmp(buf)) {
      68          440016 :       longjmp(buf, 1);
      69          440016 :     }
      70          440016 :   }
      71                 : };
      72               1 : PERF_TEST_DECLARE(TestSetjmpLongjmp)
      73                 : 
      74                 : // Measure the overhead of the clock_gettime() call that the test
      75                 : // framework uses.  This is also an example of a not-quite-trivial
      76                 : // NaCl syscall which writes to untrusted address space and might do a
      77                 : // host OS syscall.
      78               6 : class TestClockGetTime : public PerfTest {
      79                 :  public:
      80                 :   virtual void run() {
      81         5630686 :     struct timespec time;
      82        16892058 :     ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &time), 0);
      83         5630686 :   }
      84                 : };
      85               1 : PERF_TEST_DECLARE(TestClockGetTime)
      86                 : 
      87                 : #if !NACL_OSX
      88                 : // We declare this as "volatile" in an attempt to prevent the compiler
      89                 : // from optimizing accesses away.
      90                 : __thread volatile int g_tls_var = 123;
      91                 : 
      92                 : class TestTlsVariable : public PerfTest {
      93                 :  public:
      94                 :   virtual void run() {
      95                 :     ASSERT_EQ(g_tls_var, 123);
      96                 :   }
      97                 : };
      98                 : PERF_TEST_DECLARE(TestTlsVariable)
      99                 : #endif
     100                 : 
     101               6 : class TestMmapAnonymous : public PerfTest {
     102                 :  public:
     103                 :   virtual void run() {
     104          525326 :     size_t size = 0x10000;
     105          525326 :     void *addr = mmap(NULL, size, PROT_READ | PROT_WRITE,
     106                 :                       MAP_ANON | MAP_PRIVATE, -1, 0);
     107         1575978 :     ASSERT_NE(addr, MAP_FAILED);
     108         1575978 :     ASSERT_EQ(munmap(addr, size), 0);
     109          525326 :   }
     110                 : };
     111               1 : PERF_TEST_DECLARE(TestMmapAnonymous)

Generated by: LCOV version 1.7