-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refer to the original PR: #2971 b/321999529 Test-On-Device: true --------- Co-authored-by: Hao <[email protected]> Co-authored-by: Yijia Zhang <[email protected]>
- Loading branch information
1 parent
b53244b
commit 7d99be1
Showing
27 changed files
with
356 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <errno.h> | ||
|
||
int* __errno_location(void) { | ||
return __errno(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef STARBOARD_ANDROID_SHARED_POSIX_EMU_INCLUDE_ERRNO_H_ | ||
#define STARBOARD_ANDROID_SHARED_POSIX_EMU_INCLUDE_ERRNO_H_ | ||
|
||
#include_next <errno.h> // The AndroidSdk version of the same file. | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// __errno_location not available in Android NDK. | ||
int* __errno_location(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // STARBOARD_ANDROID_SHARED_POSIX_EMU_INCLUDE_ERRNO_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
starboard/nplb/posix_compliance/posix_socket_errno_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2024 The Cobalt Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <errno.h> | ||
#include <netinet/in.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "starboard/common/log.h" | ||
#include "starboard/nplb/posix_compliance/posix_socket_helpers.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace starboard { | ||
namespace nplb { | ||
namespace { | ||
|
||
TEST(PosixErrnoTest, CreateInvalidSocket) { | ||
EXPECT_FALSE(socket(-1, SOCK_STREAM, IPPROTO_TCP) == 0); | ||
EXPECT_TRUE(errno == EAFNOSUPPORT); | ||
SB_DLOG(INFO) << "Failed to create invalid socket, errno = " | ||
<< strerror(errno); | ||
} | ||
|
||
TEST(PosixErrnoTest, AcceptInvalidSocket) { | ||
int invalid_socket_fd = -1; | ||
EXPECT_FALSE(accept(invalid_socket_fd, NULL, NULL) == 0); | ||
EXPECT_TRUE(errno == EBADF); | ||
SB_DLOG(INFO) << "Failed to accept invalid socket, errno = " | ||
<< strerror(errno); | ||
} | ||
|
||
TEST(PosixErrnoTest, ConnectUnavailableAddress) { | ||
int socket_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | ||
ASSERT_TRUE(socket_fd > 0); | ||
|
||
sockaddr_in6 address = {}; | ||
#if SB_HAS(IPV6) | ||
EXPECT_TRUE( | ||
PosixGetLocalAddressIPv4(reinterpret_cast<sockaddr*>(&address)) == 0 || | ||
PosixGetLocalAddressIPv6(reinterpret_cast<sockaddr*>(&address)) == 0); | ||
#else | ||
EXPECT_TRUE(PosixGetLocalAddressIPv4(reinterpret_cast<sockaddr*>(&address)) == | ||
0); | ||
#endif | ||
|
||
// Attempt to connect to an address where we expect connection to be refused | ||
connect(socket_fd, (struct sockaddr*)&address, sizeof(address)); | ||
|
||
EXPECT_TRUE(errno == ECONNREFUSED || errno == EADDRNOTAVAIL || | ||
errno == EINPROGRESS || errno == EINVAL); | ||
SB_DLOG(INFO) << "Failed to connect to unavailable address, errno = " | ||
<< strerror(errno); | ||
|
||
close(socket_fd); | ||
} | ||
} // namespace | ||
} // namespace nplb | ||
} // namespace starboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.