LCOV - code coverage report
Current view: directory - src/trusted/gdb_rsp - host_test.cc (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 66 37 56.1 %
Date: 2012-02-16 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright 2010 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can
       4                 :  * be found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #include <assert.h>
       8                 : #include <stdio.h>
       9                 : #include <stdlib.h>
      10                 : #include <string.h>
      11                 : 
      12                 : #include <string>
      13                 : #include <sstream>
      14                 : #include <vector>
      15                 : 
      16                 : #include "native_client/src/trusted/gdb_rsp/abi.h"
      17                 : #include "native_client/src/trusted/gdb_rsp/host.h"
      18                 : #include "native_client/src/trusted/gdb_rsp/session_mock.h"
      19                 : #include "native_client/src/trusted/gdb_rsp/test.h"
      20                 : 
      21                 : using gdb_rsp::Abi;
      22                 : using gdb_rsp::Host;
      23                 : using gdb_rsp::SessionMock;
      24                 : 
      25               2 : int VerifyProp(Host* host, const char *key, const char *val) {
      26               2 :   std::string out;
      27               2 :   if (!host->ReadProperty(key, &out)) {
      28               0 :     printf("Could not find key: %s.\n", key);
      29               0 :     return 1;
      30                 :   }
      31                 : 
      32               2 :   if (out != val) {
      33                 :     printf("Property mismatch\n\tVALUE:%s\n\tEXPECTED:%s\n",
      34               0 :            out.data(), val);
      35               0 :     return 1;
      36                 :   }
      37                 : 
      38               2 :   return 0;
      39                 : }
      40                 : 
      41               1 : int TestHost() {
      42               1 :   int errs = 0;
      43               1 :   SessionMock *ses = gdb_rsp::GetGoldenSessionMock(false, false);
      44               1 :   const gdb_rsp::Abi* abi = gdb_rsp::Abi::Get();
      45                 : 
      46               1 :   Host *host = new Host(ses);
      47               1 :   std::string val;
      48               2 :   if (!host->Init()) {
      49               0 :     printf("Failed to init host.\n");
      50               0 :     return 1;
      51                 :   }
      52                 : 
      53                 :   // Verify that the Init/Update transactions were
      54                 :   // correctly applied.
      55               1 :   if (!host->HasProperty("qXfer:features:read")) {
      56               0 :     printf("Missing property: qXfer:features:read\n");
      57               0 :     errs++;
      58                 :   }
      59                 : 
      60               1 :   errs += VerifyProp(host, "PacketSize", "7cf");
      61               1 :   errs += VerifyProp(host, "qXfer:libraries:read", "true");
      62               1 :   Host::Thread* thread = host->GetThread(0x1234);
      63               1 :   if (NULL == thread) {
      64               0 :     printf("Failed to find expected thead 1234.\n");
      65               0 :     errs++;
      66                 :   } else {
      67              17 :     for (uint32_t a = 0; a < abi->GetRegisterCount(); a++) {
      68              16 :       const Abi::RegDef* def = abi->GetRegisterDef(a);
      69                 :       uint64_t val;
      70              16 :       thread->GetRegister(a, &val);
      71              16 :       if (static_cast<uint32_t>(val) != a) {
      72               0 :         errs++;
      73                 :         printf("Register %s(%d) failed to match expected value: %x",
      74               0 :                def->name_, a, static_cast<int>(val));
      75               0 :         break;
      76                 :       }
      77                 :     }
      78                 :   }
      79                 : 
      80               1 :   if (host->GetStatus() != Host::HS_STOPPED) {
      81               0 :     printf("We expect to be stopped at this point.\n");
      82               0 :     errs++;
      83                 :   }
      84                 : 
      85               1 :   if (host->GetSignal() != 5) {
      86               0 :     printf("We expect to see signal 5.\n");
      87               0 :     errs++;
      88                 :   }
      89                 : 
      90               1 :   if (ses->PeekAction() != SessionMock::DISCONNECT) {
      91               0 :     printf("We did not consume all the actions.\n");
      92               0 :     errs++;
      93                 :   }
      94                 : 
      95                 :   // Pop off the DC, and continue processing.
      96               1 :   ses->GetAction();
      97                 : 
      98                 :   // Verify we are now in a running state
      99               1 :   ses->AddAction(SessionMock::SEND, "c");
     100               1 :   host->Continue();
     101                 : 
     102                 :   // We should be running, and timing out on wait
     103               1 :   if (host->GetStatus() != Host::HS_RUNNING) {
     104               0 :     printf("We expect to be running at this point.\n");
     105               0 :     errs++;
     106                 :   }
     107               1 :   if (host->WaitForBreak()) {
     108               0 :     printf("We should have timed out.\n");
     109               0 :     errs++;
     110                 :   }
     111                 : 
     112                 :   // Insert a signal 11 for us to wait on
     113               1 :   ses->AddAction(SessionMock::RECV, "S11");
     114               1 :   AddMockUpdate(ses, 0x11);
     115               1 :   if (!host->WaitForBreak()) {
     116               0 :     printf("We should have gotten a signal.\n");
     117               0 :     errs++;
     118                 :   }
     119               1 :   if (host->GetStatus() != Host::HS_STOPPED) {
     120               0 :     printf("We expect to be stopped at this point.\n");
     121               0 :     errs++;
     122                 :   }
     123               1 :   if (host->GetSignal() != 0x11) {
     124               0 :     printf("We expect to see signal 11.\n");
     125               0 :     errs++;
     126                 :   }
     127                 : 
     128               1 :   delete host;
     129               1 :   delete ses;
     130               1 :   return errs;
     131                 : }
     132                 : 

Generated by: LCOV version 1.7