1 //===- CommandTest.cpp -- command line runtime builder unit tests ---------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "flang/Optimizer/Builder/Runtime/Command.h"
10 #include "RuntimeCallTestBase.h"
11 #include "gtest/gtest.h"
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);
20 TEST_F(RuntimeCallTest
, genGetCommandArgument
) {
21 mlir::Location loc
= firBuilder
->getUnknownLoc();
22 mlir::Type intTy
= firBuilder
->getDefaultIntegerType();
23 mlir::Type boxTy
= fir::BoxType::get(firBuilder
->getNoneType());
24 mlir::Value number
= firBuilder
->create
<fir::UndefOp
>(loc
, intTy
);
25 mlir::Value value
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
26 mlir::Value length
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
27 mlir::Value errmsg
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
28 mlir::Value result
= fir::runtime::genGetCommandArgument(
29 *firBuilder
, loc
, number
, value
, length
, errmsg
);
30 checkCallOp(result
.getDefiningOp(), "_FortranAGetCommandArgument",
35 TEST_F(RuntimeCallTest
, genGetEnvVariable
) {
36 mlir::Location loc
= firBuilder
->getUnknownLoc();
37 mlir::Value name
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
38 mlir::Value value
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
39 mlir::Value length
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
40 mlir::Value trimName
= firBuilder
->create
<fir::UndefOp
>(loc
, i1Ty
);
41 mlir::Value errmsg
= firBuilder
->create
<fir::UndefOp
>(loc
, boxTy
);
42 mlir::Value result
= fir::runtime::genGetEnvVariable(
43 *firBuilder
, loc
, name
, value
, length
, trimName
, errmsg
);
44 checkCallOp(result
.getDefiningOp(), "_FortranAGetEnvVariable", /*nbArgs=*/5,
48 TEST_F(RuntimeCallTest
, genGetPID
) {
49 mlir::Location loc
= firBuilder
->getUnknownLoc();
50 mlir::Value result
= fir::runtime::genGetPID(*firBuilder
, loc
);
51 checkCallOp(result
.getDefiningOp(), "_FortranAGetPID", /*nbArgs=*/0,
52 /*addLocArgs=*/false);