Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add specific tests for {RO}Span.IndexOfAny<char>#32069

Merged
stephentoub merged 4 commits into
dotnet:masterfrom
benaadams:span-IndexOfAny-char--Tests
Sep 26, 2018
Merged

Add specific tests for {RO}Span.IndexOfAny<char>#32069
stephentoub merged 4 commits into
dotnet:masterfrom
benaadams:span-IndexOfAny-char--Tests

Conversation

@benaadams
Copy link
Copy Markdown
Member

@benaadams benaadams commented Sep 1, 2018

Supporting dotnet/coreclr#19790

/cc @krwq

Comment thread src/System.Memory/tests/ReadOnlySpan/IndexOfAny.char.cs Outdated
}

[Fact]
public static void DefaultFilledIndexOfTwo_Char()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure what is this test testing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not entirely sure either, copied it from the byte variant

Copy link
Copy Markdown

@ahsonkhan ahsonkhan Sep 20, 2018

Choose a reason for hiding this comment

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

Yep, can't make sense of it anymore. I will have to dig up what the test used to be.

I think the intention was to look for (default, x) and (x, default) in a span containing only default, and assert we always find it at the first index.

Therefore, the inner loop is unnecessary, at least the way the test is written atm:
for (int i = 0; i < length; i++)

It should just be single check. The test should look like this:

            for (int length = 0; length < byte.MaxValue; length++)
            {
                byte[] a = new byte[length];
                Span<byte> span = new Span<byte>(a);

                 int idx = span.IndexOfAny(default, 99);
                 Assert.Equal(0, idx);

                 idx = span.IndexOfAny(99, default);
                 Assert.Equal(0, idx);
            }

We can leave it as is for now and fix all the tests (byte/char/etc.) in one go outside of this PR.

Edit:

I will have to dig up what the test used to be.

Found where it originated: #17472
The loop didn't make sense then either. My recommendation above holds.

@benaadams
Copy link
Copy Markdown
Member Author

@dotnet-bot test UWP CoreCLR x64 Debug Build

@benaadams
Copy link
Copy Markdown
Member Author

Raised issue for UWP failure https://github.com/dotnet/corefx/issues/32083

Comment thread src/System.Memory/tests/ReadOnlySpan/IndexOfAny.char.cs Outdated
Comment thread src/System.Memory/tests/ReadOnlySpan/IndexOfAny.char.cs Outdated
@danmoseley
Copy link
Copy Markdown
Member

@ahsonkhan is this good to merge now?

@benaadams
Copy link
Copy Markdown
Member Author

@danmosemsft you triggered a rebuild with your comment, looks like infra not happy

10:36:10 Done building Native components
10:36:20 -- The C compiler identification is MSVC 19.14.26433.0
10:36:22 -- The CXX compiler identification is MSVC 19.14.26433.0
10:36:22 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
10:36:23 Cannot contact windows.10.amd64.clientrs4.devex.open-0913102446322-1: hudson.remoting.RequestAbortedException: java.nio.channels.ClosedChannelException
12:24:57 Cancelling nested steps due to timeout
12:24:57 Could not connect to windows.10.amd64.clientrs4.devex.open-0913102446322-1 to send interrupt signal to process
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] echo
Archiving logs in netci-archived-logs/**
[Pipeline] step
Required context class hudson.Launcher is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
[Pipeline] echo
Error during cleanup: java.lang.IllegalArgumentException: Failed to prepare archiveArtifacts step
[Pipeline] isUnix
Required context class hudson.Launcher is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
[Pipeline] echo
Some files could not be cleaned up because of running processes.  These processes will be killed immediately and cleanup will happen before the node upon node-reuse
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
Setting status of 658a5716713374ceaed027b4970b4876a04c125f to FAILURE with url https://ci3.dot.net/job/dotnet_corefx/job/master/job/windows-TGroup_netcoreapp+CGroup_Release+AGroup_x86+TestOuter_false_prtest/16424/ and message: 'Build finished. '
Using context: Windows x86 Release Build
Timeout has been exceeded
Finished: ABORTED

@benaadams
Copy link
Copy Markdown
Member Author

@dotnet-bot test NETFX x86 Release Build
@dotnet-bot test Windows x86 Release Build

@danmoseley
Copy link
Copy Markdown
Member

@mmitche why do random comments sometimes trigger rebuilds?

@mmitche
Copy link
Copy Markdown
Member

mmitche commented Sep 17, 2018

@danmosemsft The comment triggers a jenkins webhook, which causes it to compare the last built sha against the current sha. That may not be up to date, and it may cause a rebuild. Jenkins also forgets that info over time (as builds are deleted, restarts, etc.) which makes a rebuild for an old PR more likely.

@ahsonkhan
Copy link
Copy Markdown

is this good to merge now?

I haven't gotten a chance to fully review all the tests yet, but does this PR need to wait for dotnet/coreclr#19790 to get merged first?

@benaadams
Copy link
Copy Markdown
Member Author

does this PR need to wait for dotnet/coreclr#19790 to get merged first?

No; its just a copying of the byte tests to char to help validate dotnet/coreclr#19790; so before would probably be better :)

@ViktorHofer
Copy link
Copy Markdown
Member

@dotnet-bot test this please

byte[] searchForBytes = Encoding.UTF8.GetBytes(searchFor);

var index = -1;
var index = span.IndexOfAny(new ReadOnlySpan<byte>(searchForBytes));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: var => int (I realize it was like that before... but it shouldn't have been :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

{
byte[] buffers = Encoding.UTF8.GetBytes(raw);
var span = new ReadOnlySpan<byte>(buffers);
ReadOnlySpan<byte> span = new ReadOnlySpan<byte>(buffers);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW, this was fine as var. Our guidelines just outlaw it when the type isn't named on the RHS, which generally means something other than a new or a cast. But naming it in such situations is fine, too.

@stephentoub
Copy link
Copy Markdown
Member

@ahsonkhan, anything more to do here?

@benaadams
Copy link
Copy Markdown
Member Author

UWP infra issue

NuGet.targets(114,5): error : Failed to download package 'System.Linq.4.1.0' from 'https://api.nuget.org/v3-flatcontainer/system.linq/4.1.0/system.linq.4.1.0.nupkg'. [D:\j\workspace\windows-TGrou---c60886e1\external\test-runtime\XUnit.Runtime.depproj] [D:\j\workspace\windows-TGrou---c60886e1\external\test-runtime\XUnit.Runtime.depproj]
NuGet.targets(114,5): error : Response status code does not indicate success: 504 (Gateway Timeout). [D:\j\workspace\windows-TGrou---c60886e1\external\test-runtime\XUnit.Runtime.depproj] [D:\j\workspace\windows-TGrou---c60886e1\external\test-runtime\XUnit.Runtime.depproj]

@benaadams
Copy link
Copy Markdown
Member Author

@dotnet-bot test UWP NETNative x86 Release Build

Copy link
Copy Markdown

@ahsonkhan ahsonkhan left a comment

Choose a reason for hiding this comment

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

LGTM

@stephentoub stephentoub merged commit bfcfd34 into dotnet:master Sep 26, 2018
@benaadams benaadams deleted the span-IndexOfAny-char--Tests branch September 26, 2018 01:25
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Add specific tests for {RO}Span.IndexOfAny<char>

* Always test using IndexOfAny(ROS)

* No var

* Less var


Commit migrated from dotnet/corefx@bfcfd34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants