Skip to content

Commit

Permalink
Smoke Tests Codegen Working (#3155)
Browse files Browse the repository at this point in the history
Smoke tests support using smithy Interface
  • Loading branch information
sbera87 authored Oct 30, 2024
1 parent 9304072 commit 153e258
Show file tree
Hide file tree
Showing 32 changed files with 2,343 additions and 40,113 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ src/aws-cpp-sdk-core/include/aws/core/SDKConfig.h

#nuget
*.nupkg

#temp codegen files
tools/code-generation/smithy/codegen/cpp-smoke-tests/codegen_output/
20 changes: 20 additions & 0 deletions cmake/sdks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,30 @@ function(add_sdks)
endif()

add_subdirectory("${SDK_DIR}")
message(STATUS "exporting ${SDK_TARGET}")
LIST(APPEND EXPORTS "${SDK_TARGET}")
unset(SDK_TARGET)
endforeach()

file(GLOB subdirs LIST_DIRECTORIES true "${CMAKE_SOURCE_DIR}/generated/smoke-tests/*")
foreach(subdir ${subdirs})
get_filename_component(folder_name ${subdir} NAME)
message(STATUS "smoke test component: ${folder_name}")
list(FIND SDK_BUILD_LIST ${folder_name} index)

# Check if the item was found (index >= 0)
if(${index} GREATER -1)
message(STATUS "${subdir} is in SDK_BUILD_LIST at index ${index}")

if(EXISTS "${subdir}/CMakeLists.txt")
add_subdirectory(${subdir})
endif()
else()
message(STATUS "${subdir} is NOT in SDK_BUILD_LIST")
endif()

endforeach()

#testing
if(ENABLE_TESTING)
add_subdirectory(tests/testing-resources)
Expand Down
29 changes: 29 additions & 0 deletions generated/smoke-tests/RunTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/testing/AwsCppSdkGTestSuite.h>

#if defined(HAS_UMASK)
#include <sys/stat.h>
#endif

int main(int argc, char** argv)
{
#if defined(HAS_UMASK)
// In order to fix github issue at https://github.com/aws/aws-sdk-cpp/issues/232
// Created dir by this process will be set with mode 0777, so that multiple users can build on the same machine
umask(0);
#endif
Aws::Testing::RedirectHomeToTempIfAppropriate();

// Disable EC2 metadata in client configuration to avoid requests retrieving EC2 metadata in unit tests.
Aws::Testing::SaveEnvironmentVariable("AWS_EC2_METADATA_DISABLED");
Aws::Environment::SetEnv("AWS_EC2_METADATA_DISABLED", "true", 1/*override*/);

::testing::InitGoogleTest(&argc, argv);
int retVal = RUN_ALL_TESTS();

return retVal;
}
34,765 changes: 0 additions & 34,765 deletions tools/code-generation/smithy/api-descriptions/model.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ dependencies {
api(codegen.rules.engine)
implementation(codegen.aws.smoke.test.model)
api(codegen.aws.endpoints)

api(codegen.aws.iam.traits)
api(codegen.aws.cloudformation.traits)
api(codegen.guava)
implementation(codegen.lombok)
annotationProcessor(codegen.lombok)
Expand All @@ -26,7 +27,8 @@ dependencies {
testImplementation(test.junit.jupiter.api)
testRuntimeOnly(test.junit.jupiter.engine)
implementation("ch.qos.logback:logback-classic:1.4.7") // Adding Logback for SLF4J

implementation("com.google.code.gson:gson:2.10.1")// Use the latest version
implementation("com.google.guava:guava:32.1.2-jre")
}

tasks.test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
package com.amazonaws.util.awsclientsmithygenerator.generators;

import lombok.Getter;
import software.amazon.smithy.aws.smoketests.model.BaseAwsVendorParams;

// This is a wrapper class for capturing all the information we need
// either directly or after processing from smithy model file
@Getter
public final class ClientConfiguration {

private final BaseAwsVendorParams params;

public ClientConfiguration(BaseAwsVendorParams params) {
this.params = params;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
package com.amazonaws.util.awsclientsmithygenerator.generators;

import java.util.ArrayList;
import java.util.Stack;
import java.util.List;
import lombok.Data;

/*
Generic Helper class for C++ code blocks for scope management
C++ code has blocks, for example function, loops, empty blocks.
Variables defined in those blocks have their scope defined in them.
Blocks can be deeply nested.
This class manages blocks, scope of variables in such blocks
along with indentation of code defined in those blocks.
One of the use cases:
Code writer keeps adding blocks to say 5 levels, at the fifth level
if the writer wants to extract the code, all the nested blocks will be
automaticallty closed in order of the stack making top level writer not
worry about it.
*/
public class CppBlockWriter {

//preset logic for some types of blocks
public static String GetForLoopRangeInitializer(String variableName, String iterableExpr){
return String.format("for (auto %s in %s)", variableName, iterableExpr);
}

public static String GetContainerDeclaration(String containerType, String containerTemplateParam, String variableName){
return String.format("%s<%s> %s",containerType, containerTemplateParam,variableName );
}

//args will always be even number Type followed by name
public static String GetFunctionBlock(String returnType, String functionName, String... args){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.length - 1; i += 2)
{
sb.append(String.format("%s %s",args[i],args[i+1] ));
if(i + 2 < args.length )
{
sb.append(", ");
}
}
return String.format("%s %s(%s)", returnType, functionName, sb.toString());
}


public static String GetLambdaBlock(String returnType, String functionName, String... args){
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.length - 1; i += 2)
{
sb.append(String.format("%s %s",args[i],args[i+1] ));
if(i + 2 < args.length )
{
sb.append(", ");
}
}
//functionName
return String.format("auto %s = [&](%s) -> %s", functionName, sb.toString(), returnType);
}

@Data
public static class Block {
private List<String> lines;
private String linePrefix;
public Block(String header, int indentLevel)
{
lines = new ArrayList<>();
if (!header.isEmpty() )
{
addCode(header + "\n{\n", indentLevel);
}
else
{
addCode("{\n", indentLevel);
}
}

//Continue with current block
public Block(int indentLevel)
{
lines = new ArrayList<>();
addCode("\n", indentLevel);
}

public void addCode(String code, int indentLevel)
{
String linePrefix = " ".repeat(indentLevel);
//split by line and add indent. make sure to skip escaped newlines
String[] splitCode = code.split("(?<!\\\\)\\n");
for (String line : splitCode) {
lines.add(String.format("%s%s",linePrefix,line));
}
}


public List<String> getCodeLines(){
return lines;
}
}

//A block can contain multiple blocks
private Stack<Block> blockStack;
private int indentLevel;
private String codeBlock;
private boolean isRootBlockNewScope;

public CppBlockWriter(String header, int level){
indentLevel = level;
blockStack = new Stack<>();
codeBlock = new String("");
isRootBlockNewScope =true;
openCodeBlock(header);
}


public CppBlockWriter(int level){
indentLevel = level;
blockStack = new Stack<>();
codeBlock = new String("");
isRootBlockNewScope =false;
continueCodeBlock("");
}

//opens a new block
public CppBlockWriter openCodeBlock(String blockHead){
//add new block to stack
//use its string builder to add "{"
Block block = new Block(blockHead, indentLevel);
blockStack.add(block);
indentLevel++;
return this;
}

public CppBlockWriter continueCodeBlock(String code){
//add new block to stack
//use its string builder to add "{"
Block block = new Block(indentLevel);
if(blockStack.empty())
{
blockStack.add(block);
}

//merge with last block
blockStack.peek().addCode(code, indentLevel);

return this;
}


//add code to current block
public CppBlockWriter addCode(String code){
if (!blockStack.isEmpty()) {

Block top = blockStack.peek();
top.addCode(code, indentLevel);
}
return this;
}

//closes current block
public CppBlockWriter closeCodeBlock(){
List<String> codeLines = new ArrayList<String>();
//if root block is not a new scope and it is the root block,
//need not close scope then
if(blockStack.size() == 1 && !isRootBlockNewScope)
{
Block top = blockStack.peek();
top.addCode("\n", indentLevel);
codeLines = top.getCodeLines();
blockStack.pop();
}
//create string and close block with "}"
//pop block of stack
//write to prior element
//return the popped one if any
else if (!blockStack.isEmpty())
{
Block top = blockStack.peek();
indentLevel--;
top.addCode("};\n", indentLevel);
codeLines = top.getCodeLines();
blockStack.pop();
}

//after close merge with previous or update root code block
if(blockStack.isEmpty())
{
codeBlock = codeBlock.concat(String.join("\n", codeLines));
}
else
{
Block top = blockStack.peek();
top.addCode(String.join("\n", codeLines), indentLevel);
}

return this;
}

//closes all nested blocks to generate the string block
String getCode(){
//if blocks not closed close first
while(!blockStack.isEmpty())
{
closeCodeBlock();
}

return codeBlock;
}

}
Loading

0 comments on commit 153e258

Please sign in to comment.