File: get_goto_model_from_c_test.cpp

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (40 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*******************************************************************\

Module: Get goto model test

Author: Daniel Poetzl

\*******************************************************************/

#include <testing-utils/get_goto_model_from_c.h>
#include <testing-utils/use_catch.h>

TEST_CASE("Get goto model from C test", "[core]")
{
  const std::string code =
    "int g;"
    "void f(int a) { int b; }"
    "void main() {}";

  const auto goto_model = get_goto_model_from_c(code);

  const auto &function_map = goto_model.goto_functions.function_map;

  REQUIRE(function_map.find("main") != function_map.end());
  REQUIRE(function_map.find(CPROVER_PREFIX "_start") != function_map.end());
  REQUIRE(function_map.find("f") != function_map.end());

  const auto &main_instructions = function_map.at("main").body.instructions;
  REQUIRE(!main_instructions.empty());

  const auto &f_instructions = function_map.at("f").body.instructions;
  REQUIRE(f_instructions.size() >= 2);

  const auto &symbol_table = goto_model.symbol_table;

  REQUIRE(symbol_table.has_symbol("main"));
  REQUIRE(symbol_table.has_symbol(CPROVER_PREFIX "_start"));
  REQUIRE(symbol_table.has_symbol("g"));
  REQUIRE(symbol_table.has_symbol("f::a"));
  REQUIRE(symbol_table.has_symbol("f::1::b"));
}