mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-02 03:55:34 +00:00
### Description
<!-- Describe your changes. -->
Split up OpTester to separate out operator vs model testing. This led to
a lot of other cleanups/refactoring.
- create BaseTester class and derived OpTester/ModelTester classes to
limit APIs to what is applicable for each test type
- e.g. adding an attribute isn't relevant to a model test
- cleanup structure
- don't expose member variables either directly or via public methods
returning them
- split out checkers so they can be easily re-used
- refactor so there's one public Check method for comparing two OrtValue
instances containing any data type
- refactor the GradientOpTester usage
- it required a lot of OpTester internals to be exposed and no other
tests needed this
- it also returned Status through various parts which prevented the
usage of the google test macros which provide better output. change to
return void and use the macros.
- fix some other minor issues
- update some cmake files so all the source files are included
- remove some low value helpers (FetchTensor and GetShapeVector)
- remove some outdated code to allow unreleased opset versions from when
onnx opset 15 wasn't released
- move files from test/util/include/test to test/util/include
- doesn't seem to be any reason for the additional subdirectory given
they're not files use to test the code in test/util
- files were moved with no changes
### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Cleanup test infrastructure.
---------
Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "test/util/include/temp_dir.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "core/platform/env.h"
|
|
|
|
namespace onnxruntime {
|
|
namespace test {
|
|
namespace {
|
|
void CreateOrDeleteDirectory(const PathString& path, bool create, bool throw_on_fail = true) {
|
|
const auto status = create ? Env::Default().CreateFolder(path) : Env::Default().DeleteFolder(path);
|
|
EXPECT_TRUE(status.IsOK()) << "Failed to " << (create ? "create" : "delete") << "temporary directory " << path;
|
|
|
|
if (throw_on_fail) {
|
|
ORT_ENFORCE(status.IsOK());
|
|
}
|
|
}
|
|
} // namespace
|
|
|
|
TemporaryDirectory::TemporaryDirectory(const PathString& path, bool delete_if_exists)
|
|
: path_{path} {
|
|
// EXPECT and throw to fail even if anyone is catching exceptions
|
|
const bool exists = Env::Default().FolderExists(path_);
|
|
if (exists) {
|
|
if (!delete_if_exists) {
|
|
EXPECT_FALSE(exists) << "Temporary directory " << path_ << " already exists.";
|
|
ORT_ENFORCE(!exists);
|
|
}
|
|
|
|
CreateOrDeleteDirectory(path_, /* create */ false);
|
|
}
|
|
|
|
CreateOrDeleteDirectory(path_, /* create*/ true);
|
|
}
|
|
|
|
TemporaryDirectory::~TemporaryDirectory() {
|
|
// don't throw in dtor
|
|
CreateOrDeleteDirectory(path_, /* create */ false, /* throw_on_fail */ false);
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace onnxruntime
|