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 Sep 21, 2023
1 parent 589e061 commit af90fa2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
1 change: 1 addition & 0 deletions cpp/src/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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
5 changes: 4 additions & 1 deletion 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 @@ -42,6 +43,8 @@ class ExportedFuncsRegistry {

private:
static list_type& registered();

FRIEND_TEST(ExportedFuncsRegistry, RegistrationOnlyOnce);
};

#define REGISTER_EXPORTED_FUNCS(classname) \
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 af90fa2

Please sign in to comment.