1 //===- CommandTest.cpp -- command line runtime builder unit tests ---------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "flang/Optimizer/Builder/Runtime/Command.h"
10 #include "RuntimeCallTestBase.h"
11 #include "gtest/gtest.h"
12
TEST_F(RuntimeCallTest,genCommandArgumentCountTest)13 TEST_F(RuntimeCallTest, genCommandArgumentCountTest) {
14 mlir::Location loc = firBuilder->getUnknownLoc();
15 mlir::Value result = fir::runtime::genCommandArgumentCount(*firBuilder, loc);
16 checkCallOp(result.getDefiningOp(), "_FortranAArgumentCount", /*nbArgs=*/0,
17 /*addLocArgs=*/false);
18 }
19
TEST_F(RuntimeCallTest,genArgumentValue)20 TEST_F(RuntimeCallTest, genArgumentValue) {
21 mlir::Location loc = firBuilder->getUnknownLoc();
22 mlir::Type intTy = firBuilder->getDefaultIntegerType();
23 mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType());
24 mlir::Value number = firBuilder->create<fir::UndefOp>(loc, intTy);
25 mlir::Value value = firBuilder->create<fir::UndefOp>(loc, charTy);
26 mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, charTy);
27 mlir::Value result =
28 fir::runtime::genArgumentValue(*firBuilder, loc, number, value, errmsg);
29 checkCallOp(result.getDefiningOp(), "_FortranAArgumentValue", /*nbArgs=*/3,
30 /*addLocArgs=*/false);
31 }
32
TEST_F(RuntimeCallTest,genArgumentLen)33 TEST_F(RuntimeCallTest, genArgumentLen) {
34 mlir::Location loc = firBuilder->getUnknownLoc();
35 mlir::Type intTy = firBuilder->getDefaultIntegerType();
36 mlir::Value number = firBuilder->create<fir::UndefOp>(loc, intTy);
37 mlir::Value result =
38 fir::runtime::genArgumentLength(*firBuilder, loc, number);
39 checkCallOp(result.getDefiningOp(), "_FortranAArgumentLength", /*nbArgs=*/1,
40 /*addLocArgs=*/false);
41 }
42
TEST_F(RuntimeCallTest,genEnvVariableValue)43 TEST_F(RuntimeCallTest, genEnvVariableValue) {
44 mlir::Location loc = firBuilder->getUnknownLoc();
45 mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType());
46 mlir::Value name = firBuilder->create<fir::UndefOp>(loc, charTy);
47 mlir::Value value = firBuilder->create<fir::UndefOp>(loc, charTy);
48 mlir::Value trimName = firBuilder->create<fir::UndefOp>(loc, i1Ty);
49 mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, charTy);
50 mlir::Value result = fir::runtime::genEnvVariableValue(
51 *firBuilder, loc, name, value, trimName, errmsg);
52 checkCallOp(result.getDefiningOp(), "_FortranAEnvVariableValue", /*nbArgs=*/4,
53 /*addLocArgs=*/true);
54 }
55
TEST_F(RuntimeCallTest,genEnvVariableLength)56 TEST_F(RuntimeCallTest, genEnvVariableLength) {
57 mlir::Location loc = firBuilder->getUnknownLoc();
58 mlir::Type charTy = fir::BoxType::get(firBuilder->getNoneType());
59 mlir::Value name = firBuilder->create<fir::UndefOp>(loc, charTy);
60 mlir::Value trimName = firBuilder->create<fir::UndefOp>(loc, i1Ty);
61 mlir::Value result =
62 fir::runtime::genEnvVariableLength(*firBuilder, loc, name, trimName);
63 checkCallOp(result.getDefiningOp(), "_FortranAEnvVariableLength",
64 /*nbArgs=*/2, /*addLocArgs=*/true);
65 }
66