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

       1                 : /*
       2                 :  * Copyright (c) 2010 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 <stdio.h>
       8                 : #include <stdlib.h>
       9                 : #include <string.h>
      10                 : 
      11                 : #include "native_client/src/trusted/debug_stub/abi.h"
      12                 : 
      13                 : using gdb_rsp::Abi;
      14                 : 
      15               1 : int VerifyAbi(const char *name, uint32_t regs) {
      16               1 :   int errs = 0;
      17                 : 
      18               1 :   const Abi *abi = Abi::Find(name);
      19               1 :   if (NULL != abi) {
      20               1 :     uint32_t regCnt = abi->GetRegisterCount();
      21               1 :     uint32_t byteCnt= abi->GetContextSize();
      22               1 :     uint32_t bytes = 0;
      23               1 :     uint32_t loop = 0;
      24                 : 
      25               1 :     if (strcmp(abi->GetName(), name)) {
      26               0 :       printf("Incorrect name for ABI %s.\n", name);
      27               0 :       errs++;
      28                 :     }
      29                 : 
      30               1 :     if (regCnt != regs) {
      31               0 :       printf("Incorrect number of registers for ABI %s.\n", name);
      32               0 :       errs++;
      33                 :     }
      34                 : 
      35               1 :     if (abi->GetRegisterDef(regs) != NULL) {
      36               0 :       printf("Unexpected register for ABI %s.\n", name);
      37               0 :       errs++;
      38                 :     }
      39                 : 
      40               1 :     for (loop = 0; loop < regs; loop++) {
      41               1 :       const Abi::RegDef *def = abi->GetRegisterDef(loop);
      42               1 :       if (NULL == def) {
      43               0 :         printf("Missing register for ABI %s, reg %d.\n", name, loop);
      44               0 :         errs++;
      45               0 :         break;
      46                 :       }
      47                 : 
      48               1 :       if (NULL == def->name_) {
      49               0 :         printf("Missing register name for ABI %s, reg %d.\n", name, loop);
      50               0 :         errs++;
      51               0 :         break;
      52                 :       }
      53                 : 
      54               1 :       if (loop != def->index_) {
      55               0 :         printf("Index mismatch for ABI %s, reg %d.\n", name, loop);
      56               0 :         errs++;
      57               0 :         break;
      58                 :       }
      59                 : 
      60               1 :       if ((1 > def->bytes_) || (def->bytes_ > byteCnt)) {
      61               0 :         printf("Bad register size for ABI %s, reg %d.\n", name, loop);
      62               0 :         errs++;
      63               0 :         break;
      64                 :       }
      65                 : 
      66               1 :       if ((def->type_ < Abi::GENERAL) || (def->type_ >= Abi::REG_TYPE_CNT)) {
      67               0 :         printf("Illegal register type ABI %s, reg %d.\n", name, loop);
      68               0 :         errs++;
      69               0 :         break;
      70                 :       }
      71                 : 
      72               1 :       if (def->offset_ != bytes) {
      73               0 :         printf("Offset mismatch in ABI %s, reg %d.\n", name, loop);
      74               0 :         errs++;
      75               0 :         break;
      76                 :       }
      77                 : 
      78               1 :       bytes += def->bytes_;
      79               1 :     }
      80                 : 
      81               1 :     if (bytes != byteCnt) {
      82               0 :       printf("Context size mismatch for ABI %s.\n", name);
      83               0 :       errs++;
      84                 :     }
      85                 : 
      86               1 :     if (abi->GetInstPtrDef() == NULL) {
      87               0 :       printf("Missing instruction pointer for ABI %s.\n", name);
      88               0 :       errs++;
      89                 :     }
      90               1 :   } else {
      91               0 :     printf("Could not find ABI %s.\n", name);
      92               0 :     errs++;
      93                 :   }
      94               1 :   return errs;
      95               1 : }
      96                 : 
      97               1 : int TestAbi() {
      98               1 :   int errs = 0;
      99                 : 
     100                 :   // TODO(cbiffle) Figure out how to REALLY detect ARM
     101               1 :   errs += VerifyAbi("iwmmxt", 17);
     102               1 :   errs += VerifyAbi("i386", 16);
     103               1 :   errs += VerifyAbi("i386:x86-64", 24);
     104               1 :   errs += VerifyAbi("mips", 33);
     105                 : 
     106                 :   // Get the default ABI
     107               1 :   const Abi* abi = Abi::Get();
     108               1 :   if (NULL == abi) {
     109               0 :     printf("Failed to get default ABI.\n");
     110               0 :     errs++;
     111                 :   }
     112                 : 
     113               1 :   if (NULL != Abi::Find("non-existant")) {
     114               0 :     printf("Found 'non-existant' ABI.\n");
     115               0 :     errs++;
     116                 :   }
     117                 : 
     118               1 :   return errs;
     119               1 : }
     120                 : 

Generated by: LCOV version 1.7