Skip to content

Commit

Permalink
Added failing tests for redundant warnings "has no effect" on externa…
Browse files Browse the repository at this point in the history
…l function calls
  • Loading branch information
mikucionisaau committed Apr 11, 2024
1 parent 15acb20 commit 29fc3ad
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 6 deletions.
11 changes: 11 additions & 0 deletions test/external_fn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,14 @@ C_PUBLIC double calc_sum(int count, const double arr[])
return res;
}
C_PUBLIC unsigned int length(const char* str) { return std::strlen(str); }

C_PUBLIC bool fast_double(double arr[], int count)
{
for (auto i = 0; i < count; ++i)
arr[i] *= 2;
return count % 2 == 0;
}

static int number = 42;
C_PUBLIC void set_number(int a) { number = a; }
C_PUBLIC int get_number() { return number; }
29 changes: 25 additions & 4 deletions test/models/external_fn.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.5//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_5.dtd'>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.6//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_6.dtd'>
<nta>
<declaration>import "libexternal_fn" {
int square(int a);
int multiply(int a, int b);
double square_root(double c);
double power(double c, int a);
double calc_sum(int n, const double d[3]);
double calc_sum(int n, const double&amp; d[3]);
int length(const string&amp; s);
bool fast_double(double&amp; d[3], int count);
void set_number(int a);
int get_number();
};

import "libbad" {
int absent(int a);
};


const int a = 3, b = 7;
const double c = 11;
const double d[3] = { 3, 5, 7 };
Expand All @@ -25,12 +29,29 @@ const double c_r2 = square_root(square_root(c));
double c2 = power(c_r2, 4);
double d_s = calc_sum(3, d);
int l = length("123");

double dd[3] = d;

void __ON_CONSTRUCT__() {
set_number(2);
}

int number = get_number();
</declaration>
<template>
<name x="5" y="5">P</name>
<location id="id0" x="0" y="0">
<location id="id0" x="187" y="0">
</location>
<location id="id1" x="0" y="0">
<urgent/>
</location>
<init ref="id0"/>
<init ref="id1"/>
<transition id="id2">
<source ref="id1"/>
<target ref="id0"/>
<label kind="assignment" x="18" y="0">fast_double(dd, 3),
set_number(17)</label>
</transition>
</template>
<system>system P;
</system>
Expand Down
44 changes: 42 additions & 2 deletions test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,53 @@ TEST_CASE("Power expressions")
CHECK(warnings.size() == 0);
}

struct Contains
{
std::string_view text;
};

bool operator==(std::string_view text, const Contains& sub) { return text.find(sub.text) != std::string_view::npos; }
bool operator!=(std::string_view text, const Contains& sub) { return !(text == sub); }
std::ostream& operator<<(std::ostream& os, const Contains& sub) { return os << sub.text; }

enum class OS { Windows, macOS, Linux };
#ifdef _WIN32
constexpr auto target_os = OS::Windows;
#elif __linux__
constexpr auto target_os = OS::Linux;
#elif __APPLE__
constexpr auto target_os = OS::macOS;
#else
#error "Unsupported target operating system"
#endif

TEST_CASE("External functions")
{
auto doc = read_document("external_fn.xml");
REQUIRE(doc);
auto& errs = doc->get_errors();
REQUIRE(errs.size() == 3);
if constexpr (target_os == OS::Linux) {
CHECK(errs[0].msg == Contains{"libbad.so: cannot open shared object file: No such file or directory"});
CHECK(errs[0].msg == Contains{"libbad.so: cannot open shared object file: No such file or directory"});
CHECK(errs[2].msg == Contains{"undefined symbol: absent"});
} else if constexpr (target_os == OS::Windows) {
CHECK(errs[0].msg == Contains{"Failed to open dynamic library libbad.dll: error 126: Module not found."});
CHECK(errs[0].msg == Contains{"Failed to open dynamic library libbad.dll: error 126: Module not found."});
CHECK(errs[2].msg == Contains{"Failed to find symbol: error 127: Procedure not found."});
} else if constexpr (target_os == OS::macOS) {
CHECK(errs[0].msg == Contains{"libbad.dylib: cannot open shared object file: No such file or directory"});
CHECK(errs[0].msg == Contains{"libbad.dylib: cannot open shared object file: No such file or directory"});
CHECK(errs[2].msg == Contains{"undefined symbol: absent"});
} else {
REQUIRE_MESSAGE(false, "OS is not supported");
}
auto& warns = doc->get_warnings();
REQUIRE(errs.size() == 3); // "libbad" not found (x2), "absent" undefined.
CHECK(warns.size() == 0);
// TypeChecker is not run when errors are present, so we do it on our own:
auto checker = UTAP::TypeChecker{*doc};
doc->accept(checker);
REQUIRE(errs.size() == 3); // no new errors
CHECK(warns.size() == 0);
}

Expand Down Expand Up @@ -417,7 +457,7 @@ TEST_CASE("Array of structs")
REQUIRE(doc);
auto& errors = doc->get_errors();
CHECK_MESSAGE(errors.size() == 0, errors.at(0).msg);
CHECK(doc->get_warnings().size() == 0);
CHECK(doc->get_warnings().size() == 0);
}

TEST_CASE("Pre increment precedence bug")
Expand Down

0 comments on commit 29fc3ad

Please sign in to comment.