LCOV - code coverage report
Current view: directory - tests/performance - perf_test_basics.cc (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 34 34 100.0 %
Date: 2014-07-02 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               3 : class TestNull : public PerfTest {
      26                 :  public:
      27        65056081 :   virtual void run() {
      28        65056081 :   }
      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               3 : class TestHostSyscall : public PerfTest {
      44                 :  public:
      45         4691071 :   virtual void run() {
      46                 : #if NACL_LINUX
      47                 :     // Don't use getpid() here, because glibc caches the pid in userland.
      48         4691071 :     int rc = syscall(__NR_getpid);
      49                 : #elif NACL_OSX
      50                 :     // Mac OS X's libsyscall caches the result of getpid, but not getppid.
      51                 :     int rc = getppid();
      52                 : #endif
      53         4691071 :     ASSERT_GT(rc, 0);
      54         4691071 :   }
      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               3 : class TestSetjmpLongjmp : public PerfTest {
      64                 :  public:
      65         3155171 :   virtual void run() {
      66                 :     jmp_buf buf;
      67         3155171 :     if (!setjmp(buf)) {
      68         3155171 :       longjmp(buf, 1);
      69                 :     }
      70         3155171 :   }
      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               3 : class TestClockGetTime : public PerfTest {
      79                 :  public:
      80         1711766 :   virtual void run() {
      81                 :     struct timespec time;
      82         1711766 :     ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &time), 0);
      83         1711766 :   }
      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               3 : class TestTlsVariable : public PerfTest {
      93                 :  public:
      94        59697726 :   virtual void run() {
      95        59697726 :     ASSERT_EQ(g_tls_var, 123);
      96        59697726 :   }
      97                 : };
      98               1 : PERF_TEST_DECLARE(TestTlsVariable)
      99                 : #endif
     100                 : 
     101               3 : class TestMmapAnonymous : public PerfTest {
     102                 :  public:
     103          601596 :   virtual void run() {
     104          601596 :     size_t size = 0x10000;
     105                 :     void *addr = mmap(NULL, size, PROT_READ | PROT_WRITE,
     106          601596 :                       MAP_ANON | MAP_PRIVATE, -1, 0);
     107          601596 :     ASSERT_NE(addr, MAP_FAILED);
     108          601596 :     ASSERT_EQ(munmap(addr, size), 0);
     109          601596 :   }
     110                 : };
     111               1 : PERF_TEST_DECLARE(TestMmapAnonymous)

Generated by: LCOV version 1.7