blob: 5b032be3f64d0bf64ee09a2b6fad473f0177b8b7 [file] [log] [blame]
// Copyright Microsoft and CHERIoT Contributors.
// SPDX-License-Identifier: MIT
#define TEST_NAME "Global Constructor"
#include "tests.hh"
#include <global_constructors.hh>
/// A class with a non-trivial constructor and a global instance of the class.
struct X
{
/// A global incremented on construction.
static inline int setInCtor;
/// Non-trivial constructor.
X()
{
debug_log("Running global constructor");
setInCtor++;
}
} x;
/// Check that we run global constructors precisely once.
void test_global_constructors()
{
TEST(X::setInCtor == 0, "Constructor run surprisingly early");
GlobalConstructors::run();
TEST(X::setInCtor == 1, "Constructor not run");
GlobalConstructors::run();
TEST(X::setInCtor == 1, "Constructor run twice");
}