Skip to content

[csharp] Initial C# codegen tests.#32734

Merged
jtattermusch merged 2 commits intogrpc:masterfrom
tonydnewell:csharp-plugin-tests
Apr 19, 2023
Merged

[csharp] Initial C# codegen tests.#32734
jtattermusch merged 2 commits intogrpc:masterfrom
tonydnewell:csharp-plugin-tests

Conversation

@tonydnewell
Copy link
Copy Markdown
Contributor

Initial bazel tests for C# protoc and grpc_protoc_plugin.

This initial test just generated code from the proto file and compares the generated code against expected files.

I've put the tests in test/csharp/codegen as that is similar to where the C++ tests are placed, but they could be moved to
src\csharp if that is a better place.

Further tests can be added once the initial framework for the tests is agreed.

@tonydnewell
Copy link
Copy Markdown
Contributor Author

@jtattermusch for you to review. Once we're happy with how and where to write the tests I'll add tests for the new work.

@yijiem yijiem requested a review from jtattermusch April 3, 2023 22:15
@yijiem yijiem assigned jtattermusch and unassigned yijiem Apr 3, 2023
@yashykt yashykt added the lang/C# label Apr 4, 2023
@jtattermusch jtattermusch changed the title Initial C# codegen tests [csharp] Initial C# codegen tests Apr 5, 2023
Copy link
Copy Markdown
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good, but added a few comments to address. Also note that the BUILD file needs to be properly formatted (see failing sanity test) and the shell script needs to pass shellcheck (also see failing sanity test).

data = [
"//src/compiler:grpc_csharp_plugin",
"@com_google_protobuf//:protoc",
] + glob(["simple/**"]),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think glob() is considered an antipattern with bazel. It's better to simply list the actual files you'll use.

option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to use package test.csharp.codegen.simple.proto.helloworld to avoid internal conflict between .proto files.

DIFFCMD="diff --strip-trailing-cr"

# diff expected files
[ "`$DIFFCMD ${DATA_DIR}/expected/Helloworld.cs \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for now, we can get rid of Helloworld.cs and only test the code generated by grpc_csharp_plugin - which is what we should primarily be testing in this repo (we can add output of protoc as a followup if we want to).

"//src/compiler:grpc_csharp_plugin",
"@com_google_protobuf//:protoc",
] + glob(["simple/**"]),
uses_polling = False,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding

tags = [
        "no_windows",
],

will automatically skip the test on windows (and I think we want that for now).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while at it, you should probably also add noasan, notsan, noubsan, nomsan since the sanitizers are failing on the CI and we don't need any of them (at least initially).

echo >&2 "Generated code does not match for Helloworld.cs"
exit 1
}
[ "`$DIFFCMD ${DATA_DIR}/expected/HelloworldGrpc.cs \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: diff returns exit code depending on whether the files match or not. checking whether diff output is empty feels dirty.

@jtattermusch jtattermusch added the release notes: no Indicates if PR should not be in release notes label Apr 5, 2023
@tonydnewell
Copy link
Copy Markdown
Contributor Author

@jtattermusch I've updated from the review comments.
The current CI check that is failing doesn't seem to be related.

@jtattermusch
Copy link
Copy Markdown
Contributor

just as an update, I didn't forget about this but I'm working on resolving some issue that this change causes when imported to the internal codebase.

],
tags = [
"no_windows",
"noasan",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR the asan, tsan, msan and ubsan issues can also be resolved by adding //test/core/util:grpc_suppressions as a dependency I think.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for now we can leave as is.

Copy link
Copy Markdown
Contributor

@jtattermusch jtattermusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The ASAN failure is unrelated.

I think this will become mergeable once the internal change cl/524263844 is submitted (I'll then recheck and merge).

@jtattermusch
Copy link
Copy Markdown
Contributor

(I rebased and force-pushed to get a fresh test run).

@jtattermusch jtattermusch changed the title [csharp] Initial C# codegen tests [csharp] Initial C# codegen tests. Apr 19, 2023
@jtattermusch jtattermusch merged commit 25192af into grpc:master Apr 19, 2023
XuanWang-Amos pushed a commit to XuanWang-Amos/grpc that referenced this pull request May 1, 2023
Initial bazel tests for C# protoc and grpc_protoc_plugin.

This initial test just generated code from the proto file and compares
the generated code against expected files.

I've put the tests in `test/csharp/codegen` as that is similar to where
the C++ tests are placed, but they could be moved to
`src\csharp` if that is a better place.

Further tests can be added once the initial framework for the tests is
agreed.
wanlin31 pushed a commit that referenced this pull request May 18, 2023
Initial bazel tests for C# protoc and grpc_protoc_plugin.

This initial test just generated code from the proto file and compares
the generated code against expected files.

I've put the tests in `test/csharp/codegen` as that is similar to where
the C++ tests are placed, but they could be moved to
`src\csharp` if that is a better place.

Further tests can be added once the initial framework for the tests is
agreed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants