xref: /llvm-project/flang/unittests/Optimizer/Builder/Runtime/CommandTest.cpp (revision 856c38d542aee5e29884c307501bf1033a9b2e42)
1ddac11aeSJosh Mottley //===- CommandTest.cpp -- command line runtime builder unit tests ---------===//
2ddac11aeSJosh Mottley //
3ddac11aeSJosh Mottley // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ddac11aeSJosh Mottley // See https://llvm.org/LICENSE.txt for license information.
5ddac11aeSJosh Mottley // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ddac11aeSJosh Mottley //
7ddac11aeSJosh Mottley //===----------------------------------------------------------------------===//
8ddac11aeSJosh Mottley 
9ddac11aeSJosh Mottley #include "flang/Optimizer/Builder/Runtime/Command.h"
10ddac11aeSJosh Mottley #include "RuntimeCallTestBase.h"
11ddac11aeSJosh Mottley #include "gtest/gtest.h"
12ddac11aeSJosh Mottley 
13ddac11aeSJosh Mottley TEST_F(RuntimeCallTest, genCommandArgumentCountTest) {
14ddac11aeSJosh Mottley   mlir::Location loc = firBuilder->getUnknownLoc();
15ddac11aeSJosh Mottley   mlir::Value result = fir::runtime::genCommandArgumentCount(*firBuilder, loc);
16ddac11aeSJosh Mottley   checkCallOp(result.getDefiningOp(), "_FortranAArgumentCount", /*nbArgs=*/0,
17ddac11aeSJosh Mottley       /*addLocArgs=*/false);
18ddac11aeSJosh Mottley }
1938073b06SJosh Mottley 
20eb7a02eaSDiana Picus TEST_F(RuntimeCallTest, genGetCommandArgument) {
2138073b06SJosh Mottley   mlir::Location loc = firBuilder->getUnknownLoc();
2238073b06SJosh Mottley   mlir::Type intTy = firBuilder->getDefaultIntegerType();
23eb7a02eaSDiana Picus   mlir::Type boxTy = fir::BoxType::get(firBuilder->getNoneType());
2438073b06SJosh Mottley   mlir::Value number = firBuilder->create<fir::UndefOp>(loc, intTy);
25eb7a02eaSDiana Picus   mlir::Value value = firBuilder->create<fir::UndefOp>(loc, boxTy);
26eb7a02eaSDiana Picus   mlir::Value length = firBuilder->create<fir::UndefOp>(loc, boxTy);
27eb7a02eaSDiana Picus   mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, boxTy);
28eb7a02eaSDiana Picus   mlir::Value result = fir::runtime::genGetCommandArgument(
29eb7a02eaSDiana Picus       *firBuilder, loc, number, value, length, errmsg);
30eb7a02eaSDiana Picus   checkCallOp(result.getDefiningOp(), "_FortranAGetCommandArgument",
31eb7a02eaSDiana Picus       /*nbArgs=*/4,
32eb7a02eaSDiana Picus       /*addLocArgs=*/true);
33189cb7dfSjeanPerier }
34189cb7dfSjeanPerier 
3548b5a06dSLeandro Lupori TEST_F(RuntimeCallTest, genGetEnvVariable) {
365ebbcfa0SJosh Mottley   mlir::Location loc = firBuilder->getUnknownLoc();
3748b5a06dSLeandro Lupori   mlir::Value name = firBuilder->create<fir::UndefOp>(loc, boxTy);
3848b5a06dSLeandro Lupori   mlir::Value value = firBuilder->create<fir::UndefOp>(loc, boxTy);
3948b5a06dSLeandro Lupori   mlir::Value length = firBuilder->create<fir::UndefOp>(loc, boxTy);
405ebbcfa0SJosh Mottley   mlir::Value trimName = firBuilder->create<fir::UndefOp>(loc, i1Ty);
4148b5a06dSLeandro Lupori   mlir::Value errmsg = firBuilder->create<fir::UndefOp>(loc, boxTy);
4248b5a06dSLeandro Lupori   mlir::Value result = fir::runtime::genGetEnvVariable(
4348b5a06dSLeandro Lupori       *firBuilder, loc, name, value, length, trimName, errmsg);
4448b5a06dSLeandro Lupori   checkCallOp(result.getDefiningOp(), "_FortranAGetEnvVariable", /*nbArgs=*/5,
45189cb7dfSjeanPerier       /*addLocArgs=*/true);
46189cb7dfSjeanPerier }
47*de58aa83SYi Wu 
48*de58aa83SYi Wu TEST_F(RuntimeCallTest, genGetPID) {
49*de58aa83SYi Wu   mlir::Location loc = firBuilder->getUnknownLoc();
50*de58aa83SYi Wu   mlir::Value result = fir::runtime::genGetPID(*firBuilder, loc);
51*de58aa83SYi Wu   checkCallOp(result.getDefiningOp(), "_FortranAGetPID", /*nbArgs=*/0,
52*de58aa83SYi Wu       /*addLocArgs=*/false);
53*de58aa83SYi Wu }
54