summaryrefslogtreecommitdiffstats
path: root/harmony-tests/src/test
diff options
context:
space:
mode:
authorSamuel Rats <samuel.rats@gmail.com>2014-07-25 10:15:38 +0200
committerNeil Fuller <nfuller@google.com>2014-07-28 11:51:42 +0100
commitbf48d2be36b35619309c70dce565d98cc3d17b1b (patch)
tree0f754739450b90e20a7c08a68794e21a43cda968 /harmony-tests/src/test
parent7fcc50509264c3a290f26737fd98ed76497f387f (diff)
downloadlibcore-bf48d2be36b35619309c70dce565d98cc3d17b1b.zip
libcore-bf48d2be36b35619309c70dce565d98cc3d17b1b.tar.gz
libcore-bf48d2be36b35619309c70dce565d98cc3d17b1b.tar.bz2
Fix Harmony-707 test for CTS
Change the way Harmony-707 test works. We cannot check timeouts equality, as timeout is approximated by the Linux Kernel (see set_sock_timeout() in net/core/sock.c). Previously, testing with the value provided to setSoTimout() could fail, depending on the Kernel configuration: - On a device running a kernel compiled with CONFIG_HZ=100, it would work - On a device running a kernel compiled with CONFIG_HZ=250, it would not: * Kernel stored a timeout of 3 (3.49975 cast to long) *timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(1000000/HZ-1))/(1000000/HZ) with tv.tv_sec=0, tv.tv_usec=10000 (10ms), and HZ=250 * Kernel returned a timeout of 12ms v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * 1000000) / HZ with sk->sk_rcvtimeo=3 and HZ=250 Instead, we have to ensure that the timeout is not reset to the internal default timeout after calling accept(): - set a timeout - immediately retrieve it and store it (this value may differ from the previously set value) - call accept() - retrieve and check the timeout with the previously stored timeout Change-Id: I7f05c6843d9e48e6d696dca17173fce028a45a68 Signed-off-by: Samuel Rats <samuel.rats@gmail.com>
Diffstat (limited to 'harmony-tests/src/test')
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java27
1 files changed, 21 insertions, 6 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
index c1d592a..be40d0b 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/channels/ServerSocketChannelTest.java
@@ -657,20 +657,35 @@ public class ServerSocketChannelTest extends TestCase {
* @tests ServerSocketChannel#socket().getSoTimeout()
*/
public void test_accept_SOTIMEOUT() throws IOException {
- // regression test for Harmony-707
- final int SO_TIMEOUT = 10;
+ // Regression test for Harmony-707
+ // The timeout actually used may be different from the one set due to
+ // rounding by the Linux Kernel (see sock_set_timeout() in net/core/sock.c).
+ // getSoTimeout() can return a different value from the one set with
+ // setSoTimeout(). Consequently we do not check for equality with what was
+ // set.
+
ServerSocketChannel sc = ServerSocketChannel.open();
try {
sc.socket().bind(null);
+
+ // Non blocking mode, accept() will return NULL since there are no pending connections.
sc.configureBlocking(false);
+
ServerSocket ss = sc.socket();
+
+ int defaultTimeout = ss.getSoTimeout();
+ assertEquals(0, defaultTimeout);
+ // The timeout value is unimportant, providing it is large enough to be accepted
+ // by the Kernel as distinct from the default.
+ final int SO_TIMEOUT = 200;
ss.setSoTimeout(SO_TIMEOUT);
+ int nonDefaultTimeout = ss.getSoTimeout();
+ assertTrue(nonDefaultTimeout != defaultTimeout);
+
SocketChannel client = sc.accept();
- // non blocking mode, returns null since there are no pending connections.
assertNull(client);
- int soTimeout = ss.getSoTimeout();
- // Harmony fails here.
- assertEquals(SO_TIMEOUT, soTimeout);
+ // Confirm the timeout was unchanged.
+ assertEquals(nonDefaultTimeout, ss.getSoTimeout());
} finally {
sc.close();
}