brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · 80e752c Raw
87 lines · c
1//===- OmptTesterGoogleTest.h - GoogleTest header variant -------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file represents the GoogleTest-based header variant, defining the11/// actual test classes and their behavior.12///13//===----------------------------------------------------------------------===//14 15#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTTESTERGOOGLETEST_H16#define OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTTESTERGOOGLETEST_H17 18#include "AssertMacros.h"19#include "OmptAliases.h"20#include "OmptAssertEvent.h"21#include "OmptAsserter.h"22#include "OmptCallbackHandler.h"23#include "OmptTesterGlobals.h"24 25// This will allow us to override the "TEST" macro of gtest26#define GTEST_DONT_DEFINE_TEST 127#include "gtest/gtest.h"28 29namespace testing {30class GTEST_API_ OmptTestCase : public testing::Test,31                                public omptest::OmptEventGroupInterface {32public:33  std::unique_ptr<omptest::OmptSequencedAsserter> SequenceAsserter =34      std::make_unique<omptest::OmptSequencedAsserter>();35  std::unique_ptr<omptest::OmptEventAsserter> SetAsserter =36      std::make_unique<omptest::OmptEventAsserter>();37  std::unique_ptr<omptest::OmptEventReporter> EventReporter =38      std::make_unique<omptest::OmptEventReporter>();39 40protected:41  void SetUp() override {42    omptest::OmptCallbackHandler::get().subscribe(SequenceAsserter.get());43    omptest::OmptCallbackHandler::get().subscribe(SetAsserter.get());44    omptest::OmptCallbackHandler::get().subscribe(EventReporter.get());45  }46 47  void TearDown() override {48    // Actively flush potential in-flight trace records49    flush_traced_devices();50 51    // Remove subscribers to not be notified of events after test execution.52    omptest::OmptCallbackHandler::get().clearSubscribers();53 54    // This common testcase must not encounter any failures.55    if (SequenceAsserter->checkState() == omptest::AssertState::Fail ||56        SetAsserter->checkState() == omptest::AssertState::Fail)57      ADD_FAILURE();58  }59};60 61class GTEST_API_ OmptTestCaseXFail : public testing::OmptTestCase {62protected:63  void TearDown() override {64    // Actively flush potential in-flight trace records65    flush_traced_devices();66 67    // Remove subscribers to not be notified of events after test execution.68    omptest::OmptCallbackHandler::get().clearSubscribers();69 70    // This eXpectedly failing testcase has to encounter at least one failure.71    if (SequenceAsserter->checkState() == omptest::AssertState::Pass &&72        SetAsserter->checkState() == omptest::AssertState::Pass)73      ADD_FAILURE();74  }75};76} // namespace testing77 78#define TEST(test_suite_name, test_name)                                       \79  GTEST_TEST_(test_suite_name, test_name, ::testing::OmptTestCase,             \80              ::testing::internal::GetTypeId<::testing::OmptTestCase>())81 82#define TEST_XFAIL(test_suite_name, test_name)                                 \83  GTEST_TEST_(test_suite_name, test_name, ::testing::OmptTestCaseXFail,        \84              ::testing::internal::GetTypeId<::testing::OmptTestCaseXFail>())85 86#endif // include guard87