LCOV - code coverage report
Current view: directory - src/trusted/validator/x86 - halt_trim_tests.cc (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 37 37 100.0 %
Date: 2014-09-25 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2011 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                 : // Unit tests for code in halt_trim.c
       8                 : 
       9                 : #ifndef NACL_TRUSTED_BUT_NOT_TCB
      10                 : #error("This file is not meant for use in the TCB")
      11                 : #endif
      12                 : 
      13                 : #include "gtest/gtest.h"
      14                 : #include "native_client/src/include/nacl_macros.h"
      15                 : #include "native_client/src/shared/platform/nacl_log.h"
      16                 : #include "native_client/src/trusted/validator/x86/halt_trim.h"
      17                 : #include "native_client/src/trusted/validator/x86/ncinstbuffer.h"
      18                 : 
      19                 : 
      20                 : namespace {
      21                 : 
      22                 : // Test harness for routines in halt_trim.c.
      23                 : class HaltTrimTests : public ::testing::Test {
      24                 :  protected:
      25               1 :   HaltTrimTests() {}
      26                 : };
      27                 : 
      28                 : // Show that if the file ends with less than the minimum number of halts,
      29                 : // no trimming occurs.
      30               3 : TEST_F(HaltTrimTests, TrimSmallHaltSegment) {
      31                 :   uint8_t small_test[] = {
      32               1 :     0xf4, 0xf4, 0xf4, 0xf4
      33               1 :   };
      34               1 :   NaClMemorySize small_test_size = NACL_ARRAY_SIZE(small_test);
      35                 : 
      36                 :   EXPECT_EQ(small_test_size,
      37               1 :             NCHaltTrimSize(small_test, small_test_size, 16));
      38               1 : }
      39                 : 
      40                 : // Show that we trim to the nearest 32 byte boundary if there
      41                 : // are a lot of halts.
      42               3 : TEST_F(HaltTrimTests, TrimManyHaltsTo32Boundary) {
      43                 :   NaClMemorySize size;
      44                 :   uint8_t large_test[] = {
      45               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      46               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      47               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      48               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      49               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      50               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      51               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      52               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      53               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      54               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      55                 :   };
      56               1 :   NaClMemorySize large_test_size = NACL_ARRAY_SIZE(large_test);
      57                 : 
      58               1 :   size = large_test_size;
      59               1 :   EXPECT_EQ((NaClMemorySize) 32, NCHaltTrimSize(large_test, size, 32));
      60                 : 
      61               1 :   size = large_test_size - 40;
      62               1 :   EXPECT_EQ((NaClMemorySize) 32, NCHaltTrimSize(large_test, size, 32));
      63               1 : }
      64                 : 
      65                 : // Show that if rounding to the nearest block alignment is too big,
      66                 : // we don't change the size.
      67               3 : TEST_F(HaltTrimTests, TrimFailsIfBlockAlignToBig) {
      68                 :   uint8_t large_test[40] = {
      69               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      70               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      71               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      72               1 :     0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4, 0xf4,
      73                 :   };
      74                 : 
      75               1 :   EXPECT_EQ((NaClMemorySize) 32,  NCHaltTrimSize(large_test, 40, 32));
      76               1 :   EXPECT_EQ((NaClMemorySize) 20,  NCHaltTrimSize(large_test, 20, 32));
      77               1 : }
      78                 : 
      79                 : };  // anonymous namespace
      80                 : 
      81               1 : int main(int argc, char *argv[]) {
      82               1 :   NaClLogModuleInit();
      83               1 :   testing::InitGoogleTest(&argc, argv);
      84               1 :   return RUN_ALL_TESTS();
      85               1 : }

Generated by: LCOV version 1.7