Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TestModels): Resource #103

Merged
merged 47 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4a5d2c2
test(resource): init testing of resource shim in C#
texastony Jan 30, 2023
a74aaa9
fix(resources): polymorph's smithydotnet does not handle bigInit or b…
texastony Jan 30, 2023
ee3e4b0
feat: init Makefile for test
texastony Jan 31, 2023
df4a884
chore: ignore JetBrains
texastony Jan 31, 2023
e1b2cc3
fix: resources.smithy
texastony Jan 31, 2023
f144f7d
fix: smithy-polymorph call's Model must be a directory
texastony Jan 31, 2023
93d66b6
chore: ignore generate types files
texastony Jan 31, 2023
915e470
chore: ignore generated dafny in tests
texastony Jan 31, 2023
717ccd2
fix: Polymorph smithy-dafny MUST write to Model
texastony Jan 31, 2023
19ff9bf
Merge branch 'main-1.x' into tony/test-resources
texastony Jan 31, 2023
9c0aee2
Merge branch 'main-1.x' into tony/test-resources
texastony Jan 31, 2023
d7518c1
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 1, 2023
fa0c8d6
fix: Service needs a concrete error
texastony Feb 2, 2023
f495b3d
feat: Simple implementaiton
texastony Feb 2, 2023
1af036c
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 2, 2023
4fd0bfc
feat: Simple Resource Service
texastony Feb 2, 2023
e9060c4
refactor: remove un-needed post-conditions
texastony Feb 2, 2023
6fa9de7
feat: compile impl to C#
texastony Feb 2, 2023
f073948
wip: test the implementation
texastony Feb 3, 2023
4e7cf00
wip: transpile_net_test still fails w/ very simple test
texastony Feb 3, 2023
9cd0b43
Merge branch 'main-1.x' of github.com:awslabs/polymorph into tony/tes…
texastony Feb 3, 2023
813dc9e
wip: transpile_net_test still fails w/ very simple test
texastony Feb 3, 2023
77b53ac
wip: transpile_net_test still fails w/ very simple test
texastony Feb 3, 2023
ba5b980
wip: trans_net_test still fails w/o Independent Config
texastony Feb 3, 2023
ca735c2
debug: force check in Types
texastony Feb 3, 2023
d42449f
revert: debug: force check in Types
texastony Feb 3, 2023
e64a588
debug: force check in Types
texastony Feb 3, 2023
40ecc9a
fix: work around issue in f073948
texastony Feb 3, 2023
47d5e44
test: restore complete service testing
texastony Feb 3, 2023
aa765c8
fix: remove Model/...Types.dfy
texastony Feb 3, 2023
30fe621
fix(csproj): include Extern in test
texastony Feb 3, 2023
21db487
wip: Test Wrapped Service
texastony Feb 3, 2023
306cbaf
issue: broken wrapped C# code
texastony Feb 3, 2023
fa49b2b
debug: try forcing non-NativeWrapper conversion
texastony Feb 3, 2023
70beb46
debug: try forcing NativeWrapper conversion
texastony Feb 4, 2023
09aafe2
issue: WrappedCodegen's NativeWrapper assumes Exception name
texastony Feb 4, 2023
bbe673d
fix: issue in 09aafe2
texastony Feb 4, 2023
dc44957
style: reformat C# for better comparison
texastony Feb 4, 2023
6fdb22b
style: run dotnet format
texastony Feb 6, 2023
19493c3
feat(TestModels): Resource
texastony Feb 13, 2023
6e4d07f
fix(smithy-dotnet): Local Service Wrapper
texastony Feb 13, 2023
565ac6c
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 13, 2023
055a1ed
style(TestModels): Resource
texastony Feb 13, 2023
be67a87
refactor(TestModels): Resource
texastony Feb 13, 2023
343c96f
Merge branch 'main-1.x' into tony/test-resources
texastony Feb 23, 2023
fe10052
ci: add TestModel/Resource to CI
texastony Feb 23, 2023
705ccb6
feat: README for TestModel/Resource
texastony Feb 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TestModels/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@

# JetBrains
**/.idea/
**/Folder.DotSettings.user
16 changes: 16 additions & 0 deletions TestModels/Resource/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

CORES=2

include ../SharedMakefile.mk

NAMESPACE=simple.resources

# This project has no dependencies
# DEPENDENT-MODELS:=
# LIBRARIES :=
transpile_net_dependencies:

format_net:
pushd runtimes/net && dotnet format && popd
83 changes: 83 additions & 0 deletions TestModels/Resource/Model/resources.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
namespace simple.resources

@aws.polymorph#localService(
sdkId: "SimpleResources",
config: SimpleResourcesConfig,
)
service SimpleResources {
version: "2021-11-01",
resources: [],
operations: [ GetResources ],
errors: [ SimpleResourcesException ],
}

structure SimpleResourcesConfig {
@required @length(min: 1) name: String
}

// This operation MUST
// return the values given in the Resources.
// The internal config MUST somehow differ,
// and this additional information MUST be returned.
operation GetResources {
input: GetResourcesInput,
output: GetResourcesOutput,
}

structure GetResourcesInput {
value: String
}

structure GetResourcesOutput {
@required
output: SimpleResourceReference
}

@aws.polymorph#reference(resource: SimpleResource)
structure SimpleResourceReference {}

resource SimpleResource {
operations: [ GetResourceData ]
}

operation GetResourceData {
input: GetResourceDataInput,
output: GetResourceDataOutput,
}

structure GetResourceDataInput {
blobValue: Blob,
booleanValue: Boolean,
stringValue: String,
// byteValue: Byte,
// shortValue: Short,
integerValue: Integer,
longValue: Long,
// floatValue: Float,
// doubleValue: Double,
// bigIntegerValue: BigInteger,
// bigDecimalValue: BigDecimal,
// timestampValue: Timestamp,
}

structure GetResourceDataOutput {
blobValue: Blob,
booleanValue: Boolean,
stringValue: String,
// byteValue: Byte,
// shortValue: Short,
integerValue: Integer,
longValue: Long,
// floatValue: Float,
// doubleValue: Double,
// bigIntegerValue: BigInteger,
// bigDecimalValue: BigDecimal,
// timestampValue: Timestamp,
}

@error("client")
structure SimpleResourcesException {
@required
message: String,
}

29 changes: 29 additions & 0 deletions TestModels/Resource/runtimes/net/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
###############################
# Core EditorConfig Options #
# See https://github.com/dotnet/format/blob/main/docs/Supported-.editorconfig-options.md
###############################
root = true
# All files
[*]
indent_style = space

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 2
insert_final_newline = true

# Rider is wrong, dotnet_diagnostic is supported
# noinspection EditorConfigKeyCorrectness
[*.{cs,vb}]
dotnet_diagnostic.CS0436.severity = none # The type <> ... conflicts with the imported type <> in ...
dotnet_diagnostic.CS0162.severity = none # Unreachable code detected
dotnet_diagnostic.CS0618.severity = none # obsolete
dotnet_diagnostic.CS0168.severity = none # Unused variable
41 changes: 41 additions & 0 deletions TestModels/Resource/runtimes/net/Extern/__defualt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

using Wrappers_Compile;
using Simple.Resources;
using Simple.Resources.Wrapped;
using Dafny.Simple.Resources.Types;
using TypeConversion = Simple.Resources.TypeConversion;
namespace Dafny.Simple.Resources
{
public partial class __default
{
public static
Wrappers_Compile._IResult<
SimpleResources_Compile.SimpleResourcesClient, Dafny.Simple.Resources.Types._IError
> SimpleResources(Dafny.Simple.Resources.Types._ISimpleResourcesConfig config)
{
return SimpleResources_Compile.__default.SimpleResources(config);
}
}
}

namespace Dafny.Simple.Resources.Wrapped
{
public partial class __default
{
public static _IResult<
Types.ISimpleResourcesClient, Types._IError
> WrappedSimpleResources(Types._ISimpleResourcesConfig config)
{
var wrappedConfig =
TypeConversion.FromDafny_N6_simple__N9_resources__S21_SimpleResourcesConfig(
config);
var impl = new SimpleResources(wrappedConfig);
var wrappedClient = new SimpleResourcesShim(impl);
return Result<
Types.ISimpleResourcesClient, Types._IError
>.create_Success(wrappedClient);
}
}
}
31 changes: 31 additions & 0 deletions TestModels/Resource/runtimes/net/SimpleResources.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>SimpleResources</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<TargetFrameworks>net6.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DafnyRuntime" Version="3.10.0.41215" />
<!--
System.Collections.Immutable can be removed once dafny.msbuild is updated with
https://github.com/dafny-lang/dafny.msbuild/pull/10 and versioned
-->
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
<!-- Work around for dafny-lang/dafny/issues/1951; remove once resolved -->
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

<Compile Include="Extern/**/*.cs" />
<Compile Include="Generated/**/*.cs" />
<Compile Include="ImplementationFromDafny.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../../../dafny-dependencies/StandardLibrary/runtimes/net/STD.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>SimpleResourcesTest</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<TargetFrameworks>net6.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<OutputType>Exe</OutputType>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<!--
System.Collections.Immutable can be removed once dafny.msbuild is updated with
https://github.com/dafny-lang/dafny.msbuild/pull/10 and versioned
-->
<PackageReference Include="System.Collections.Immutable" Version="1.7.0" />
<!-- Work around for dafny-lang/dafny/issues/1951; remove once resolved -->
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

<ProjectReference Include="../SimpleResources.csproj" />
<Compile Include="../Generated/**" />
<Compile Include="../Extern/**" />
<Compile Include="TestsFromDafny.cs" />
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions TestModels/Resource/src/Index.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

include "../Model/SimpleResourcesTypes.dfy"
include "./SimpleResourcesOperations.dfy"

module SimpleResources refines AbstractSimpleResourcesService
{
import Operations = SimpleResourcesOperations

function method DefaultSimpleResourcesConfig(): SimpleResourcesConfig
{
SimpleResourcesConfig(
name := "default"
)
}

method SimpleResources(
config: SimpleResourcesConfig
) returns (
res: Result<SimpleResourcesClient, Error>
)
{
var internalConfig: Operations.InternalConfig := Operations.Config(
name := config.name
);

if Operations.ValidInternalConfig?(internalConfig) {
var client := new SimpleResourcesClient(
config := internalConfig
);
return Success(client);
} else {
return Failure(Types.SimpleResourcesException(
message := "Length of name must be greater than 0")
);
}
}

class SimpleResourcesClient...
{
predicate ValidState()
{
&& Operations.ValidInternalConfig?(config)
&& History !in Operations.ModifiesInternalConfig(config)
&& Modifies == Operations.ModifiesInternalConfig(config) + {History}
}

constructor(
config: Operations.InternalConfig
)
{
this.config := config;
History := new ISimpleResourcesClientCallHistory();
Modifies := Operations.ModifiesInternalConfig(config) + {History};
}
}
}

69 changes: 69 additions & 0 deletions TestModels/Resource/src/SimpleResource.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

include "../Model/SimpleResourcesTypes.dfy"

module SimpleResource {
import opened StandardLibrary
import opened Wrappers
import Types = SimpleResourcesTypes

class SimpleResource extends Types.ISimpleResource
{
predicate ValidState()
ensures ValidState() ==> History in Modifies
{
&& History in Modifies
}

const name: string
const value: Option<string>

constructor (
value: Option<string>,
name: string
)
requires |name| > 0
ensures this.value == value
ensures this.name == name
ensures ValidState() && fresh(History) && fresh(Modifies)
{
this.value := value;
this.name := name;

History := new Types.ISimpleResourceCallHistory();
Modifies := {History};
}

predicate GetResourceDataEnsuresPublicly(
input: Types.GetResourceDataInput,
output: Result<Types.GetResourceDataOutput, Types.Error>
) {true}

method GetResourceData'(
input: Types.GetResourceDataInput
) returns (
output: Result<Types.GetResourceDataOutput, Types.Error>
)
requires ValidState()
modifies Modifies - {History}
decreases Modifies - {History}
ensures && ValidState()
ensures GetResourceDataEnsuresPublicly(input, output)
ensures unchanged(History)
{
var rtnString: string := if input.stringValue.Some? then
this.name + " " + input.stringValue.value
else
this.name;
var rtn: Types.GetResourceDataOutput := Types.GetResourceDataOutput(
blobValue := input.blobValue,
booleanValue := input.booleanValue,
stringValue := Option.Some(rtnString),
texastony marked this conversation as resolved.
Show resolved Hide resolved
integerValue := input.integerValue,
longValue := input.longValue
);
return Success(rtn);
}
}
}
Loading