Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Black box testing of cvc5::InteractiveShell for sygus 11 : : */ 12 : : 13 : : #include <cvc5/cvc5.h> 14 : : #include <cvc5/cvc5_parser.h> 15 : : 16 : : #include <memory> 17 : : #include <sstream> 18 : : #include <vector> 19 : : 20 : : #include "main/command_executor.h" 21 : : #include "main/interactive_shell.h" 22 : : #include "options/base_options.h" 23 : : #include "options/language.h" 24 : : #include "options/options.h" 25 : : #include "test.h" 26 : : 27 : : using namespace cvc5::parser; 28 : : 29 : : namespace cvc5::internal { 30 : : namespace test { 31 : : 32 : : class TestMainBlackInteractiveShellSygus : public TestInternal 33 : : { 34 : : protected: 35 : 1 : void SetUp() override 36 : : { 37 : 1 : TestInternal::SetUp(); 38 : : 39 : 1 : d_sin = std::make_unique<std::stringstream>(); 40 : 1 : d_sout = std::make_unique<std::stringstream>(); 41 : : 42 : 1 : d_solver.reset(new cvc5::Solver(d_tm)); 43 : 1 : d_solver->setOption("input-language", "sygus2"); 44 : 1 : d_cexec.reset(new main::CommandExecutor(d_solver)); 45 : 1 : } 46 : : 47 : 1 : void TearDown() override 48 : : { 49 : 1 : d_sin.reset(nullptr); 50 : 1 : d_sout.reset(nullptr); 51 : : // ensure that command executor is destroyed before solver 52 : 1 : d_cexec.reset(nullptr); 53 : 1 : d_solver.reset(nullptr); 54 : 1 : } 55 : : 56 : : /** 57 : : * Read up to maxIterations+1 from the shell and throw an assertion error if 58 : : * it's fewer than minIterations and more than maxIterations. Note that an 59 : : * empty string followed by EOF may be returned as an empty command, and 60 : : * not nullptr (subsequent calls to readAndExecCommands() should return 61 : : * nullptr). E.g., "(synth-fun f (Int) Int)\n" may return two commands: the 62 : : * synth-fun, followed by an empty command, followed by nullptr. 63 : : */ 64 : 1 : void countCommands(InteractiveShell& shell, 65 : : uint32_t minIterations, 66 : : uint32_t maxIterations) 67 : : { 68 : 1 : uint32_t n = 0; 69 [ + - ]: 3 : while (n <= maxIterations) 70 : : { 71 [ + + ]: 3 : if (!shell.readAndExecCommands()) 72 : : { 73 : 1 : break; 74 : : } 75 : 2 : n++; 76 : : } 77 [ - + ][ + - ]: 1 : ASSERT_LE(n, maxIterations); 78 [ - + ][ + - ]: 1 : ASSERT_GE(n, minIterations); 79 : : } 80 : : 81 : : std::unique_ptr<std::stringstream> d_sin; 82 : : std::unique_ptr<std::stringstream> d_sout; 83 : : std::unique_ptr<main::CommandExecutor> d_cexec; 84 : : cvc5::TermManager d_tm; 85 : : std::unique_ptr<cvc5::Solver> d_solver; 86 : : }; 87 : : 88 : 4 : TEST_F(TestMainBlackInteractiveShellSygus, test_sygus) 89 : : { 90 : 1 : *d_sin << "(synth-fun f (Int) Int)\n\n" << std::flush; 91 : 1 : InteractiveShell shell(d_cexec.get(), *d_sin, *d_sout); 92 : 1 : countCommands(shell, 1, 2); 93 : 1 : } 94 : : 95 : : } // namespace test 96 : : } // namespace cvc5::internal