|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +#include <gtest/gtest.h> |
| 19 | +#include <llvm/IR/DataLayout.h> |
| 20 | +#include <llvm/TargetParser/Host.h> |
| 21 | + |
| 22 | +#include "gandiva/llvm_generator.h" |
| 23 | +#include "gandiva/tests/test_util.h" |
| 24 | + |
| 25 | +namespace gandiva { |
| 26 | + |
| 27 | +class TestTargetDataLayout : public ::testing::Test { |
| 28 | + protected: |
| 29 | + void SetUp() override {} |
| 30 | +}; |
| 31 | + |
| 32 | +// Test that verifies the target data layout string representation |
| 33 | +// is consistent with the CPU architecture. This test is portable |
| 34 | +// across different architectures. |
| 35 | +TEST_F(TestTargetDataLayout, VerifyDataLayoutForArchitecture) { |
| 36 | + // Create an LLVM generator with default configuration |
| 37 | + ASSERT_OK_AND_ASSIGN(auto generator, LLVMGenerator::Make(TestConfiguration(), false)); |
| 38 | + |
| 39 | + // Get the module from the generator |
| 40 | + llvm::Module* module = generator->module(); |
| 41 | + ASSERT_NE(module, nullptr); |
| 42 | + |
| 43 | + // Get the data layout from the module |
| 44 | + const llvm::DataLayout& data_layout = module->getDataLayout(); |
| 45 | + std::string data_layout_str = data_layout.getStringRepresentation(); |
| 46 | + |
| 47 | + // Verify that the data layout string is not empty |
| 48 | + EXPECT_FALSE(data_layout_str.empty()); |
| 49 | + |
| 50 | + // Get the host CPU architecture information |
| 51 | + std::string host_cpu = llvm::sys::getHostCPUName().str(); |
| 52 | + std::string triple = llvm::sys::getDefaultTargetTriple(); |
| 53 | + |
| 54 | + // Log the information for debugging |
| 55 | + std::cout << "Host CPU: " << host_cpu << std::endl; |
| 56 | + std::cout << "Target Triple: " << triple << std::endl; |
| 57 | + std::cout << "Data Layout: " << data_layout_str << std::endl; |
| 58 | + |
| 59 | + // Verify that the data layout string is not empty |
| 60 | + EXPECT_FALSE(data_layout_str.empty()); |
| 61 | + |
| 62 | + } |
| 63 | +} // namespace gandiva |
| 64 | + |
0 commit comments