<commit_before>// Copyright 2013-2015 Stanford University
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "src/sandbox/sandbox.h"
#include "src/validator/bounded.h"

namespace stoke {

class BoundedValidatorBaseTest : public ::testing::Test { 

  public:

    BoundedValidatorBaseTest() {
      solver = new Cvc4Solver();
      sandbox = new Sandbox();
      validator = new BoundedValidator(*solver);
      validator->set_bound(8);
      validator->set_sandbox(sandbox);
    }

    ~BoundedValidatorBaseTest() {
      delete validator;
      delete solver;
      delete sandbox;
    }

  protected:

    static x64asm::RegSet all() {
      auto rs = x64asm::RegSet::all_gps() | x64asm::RegSet::all_ymms();
      rs = rs + x64asm::eflags_cf + x64asm::eflags_zf + x64asm::eflags_pf + x64asm::eflags_of + x64asm::eflags_sf;
      return rs;
    }

    void fail() {
      FAIL();
    }

    Cfg make_cfg(std::stringstream& ss, x64asm::RegSet di = all(), x64asm::RegSet lo = all()) {
      x64asm::Code c;
      ss >> c;
      if(ss.fail()) {
        std::cerr << "Parsing error!" << std::endl;
        std::cerr << cpputil::fail_msg(ss) << std::endl;
        fail();
      }
      return Cfg(c, di, lo);
    }

    void add_testcases(int count) {
      for (int i = 0; i < count; ++i) {
        sandbox->insert_input(get_state());
      }
    }

    void add_testcases(int count, const Cfg& cfg) {
      for (int i = 0; i < count; ++i) {
        sandbox->insert_input(get_state(cfg));
      }
    }

    CpuState get_state() {
      CpuState cs;
      StateGen sg(sandbox);
      sg.get(cs);
      return cs;
    }

    CpuState get_state(const Cfg& cfg) {
      CpuState cs;
      StateGen sg(sandbox);
      sg.get(cs, cfg);
      return cs;
    }

    SMTSolver* solver;
    BoundedValidator* validator;
    Sandbox* sandbox;
};

TEST_F(BoundedValidatorBaseTest, NoLoopsPasses) {
<commit_msg>astyle<commit_after>// Copyright 2013-2015 Stanford University
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "src/sandbox/sandbox.h"
#include "src/validator/bounded.h"

namespace stoke {

class BoundedValidatorBaseTest : public ::testing::Test {

public:

  BoundedValidatorBaseTest() {
    solver = new Cvc4Solver();
    sandbox = new Sandbox();
    validator = new BoundedValidator(*solver);
    validator->set_bound(8);
    validator->set_sandbox(sandbox);
  }

  ~BoundedValidatorBaseTest() {
    delete validator;
    delete solver;
    delete sandbox;
  }

protected:

  static x64asm::RegSet all() {
    auto rs = x64asm::RegSet::all_gps() | x64asm::RegSet::all_ymms();
    rs = rs + x64asm::eflags_cf + x64asm::eflags_zf + x64asm::eflags_pf + x64asm::eflags_of + x64asm::eflags_sf;
    return rs;
  }

  void fail() {
    FAIL();
  }

  Cfg make_cfg(std::stringstream& ss, x64asm::RegSet di = all(), x64asm::RegSet lo = all()) {
    x64asm::Code c;
    ss >> c;
    if(ss.fail()) {
      std::cerr << "Parsing error!" << std::endl;
      std::cerr << cpputil::fail_msg(ss) << std::endl;
      fail();
    }
    return Cfg(c, di, lo);
  }

  void add_testcases(int count) {
    for (int i = 0; i < count; ++i) {
      sandbox->insert_input(get_state());
    }
  }

  void add_testcases(int count, const Cfg& cfg) {
    for (int i = 0; i < count; ++i) {
      sandbox->insert_input(get_state(cfg));
    }
  }

  CpuState get_state() {
    CpuState cs;
    StateGen sg(sandbox);
    sg.get(cs);
    return cs;
  }

  CpuState get_state(const Cfg& cfg) {
    CpuState cs;
    StateGen sg(sandbox);
    sg.get(cs, cfg);
    return cs;
  }

  SMTSolver* solver;
  BoundedValidator* validator;
  Sandbox* sandbox;
};

TEST_F(BoundedValidatorBaseTest, NoLoopsPasses) {

{'fraction_non_alphanumeric': 0.12819420783645655, 'fraction_numerical': 0.016183986371379896, 'mean_word_length': 2.9537037037037037, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6312779', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1569, 'n_words': 426}