Skip to content

Commit

Permalink
Add minimum test case for verifying exported function registration on…
Browse files Browse the repository at this point in the history
…ly happens once.
  • Loading branch information
niyue committed Oct 5, 2023
1 parent 470f86d commit 3cf1766
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions cpp/src/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ add_gandiva_test(internals-test
tree_expr_test.cc
encrypt_utils_test.cc
expr_decomposer_test.cc
exported_funcs_registry_test.cc
expression_registry_test.cc
selection_vector_test.cc
lru_cache_test.cc
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/exported_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <vector>
#include "gandiva/visibility.h"

namespace gandiva {

Expand Down Expand Up @@ -61,6 +62,5 @@ class ExportedHashFunctions : public ExportedFuncsBase {
void AddMappings(Engine* engine) const override;
};

void RegisterExportedFuncs();

GANDIVA_EXPORT void RegisterExportedFuncs();
} // namespace gandiva
2 changes: 1 addition & 1 deletion cpp/src/gandiva/exported_funcs_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace gandiva {

void ExportedFuncsRegistry::AddMappings(Engine* engine) {
for (auto entry : registered()) {
for (const auto& entry : registered()) {
entry->AddMappings(engine);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/exported_funcs_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
#include <vector>

#include <gandiva/engine.h>
#include <gandiva/visibility.h>

namespace gandiva {

class ExportedFuncsBase;

/// Registry for classes that export functions which can be accessed by
/// LLVM/IR code.
class ExportedFuncsRegistry {
class GANDIVA_EXPORT ExportedFuncsRegistry {
public:
using list_type = std::vector<std::shared_ptr<ExportedFuncsBase>>;

Expand All @@ -40,7 +41,6 @@ class ExportedFuncsRegistry {
return true;
}

private:
static list_type& registered();
};

Expand Down
28 changes: 28 additions & 0 deletions cpp/src/gandiva/exported_funcs_registry_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "gandiva/exported_funcs_registry.h"
#include <gtest/gtest.h>
#include "gandiva/exported_funcs.h"

namespace gandiva {
TEST(ExportedFuncsRegistry, RegistrationOnlyOnce) {
gandiva::RegisterExportedFuncs();
auto const& registered_list = ExportedFuncsRegistry::registered();
EXPECT_EQ(registered_list.size(), 6);
}
} // namespace gandiva

0 comments on commit 3cf1766

Please sign in to comment.