You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2020/09/17 19:35:16 UTC

[GitHub] [trafficserver] ywkaras opened a new pull request #7203: Convert PluginVC Regression Test to an Au Test.

ywkaras opened a new pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493069554



##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       How do you control the maximum wait time?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] bneradt commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
bneradt commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493157797



##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       I believe you should be able to use [StartupTimeout](https://autestsuite.bitbucket.io/API/process.html?highlight=timeout#autest.testenities.process.Process.StartupTimeout).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-698554021


   @SolidWallOfCode you may want to look at this as it involves a strategy of moving some unit testing from Catch to Au testing.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493015424



##########
File path: iocore/net/P_Net.h
##########
@@ -104,7 +104,6 @@ extern RecRawStatBlock *net_rsb;
 #include "P_UnixPollDescriptor.h"
 #include "P_Socks.h"
 #include "P_CompletionUtil.h"
-#include "P_NetVCTest.h"

Review comment:
       Had to correct many improper dependencies on the fact that P_NetVCTest.h is included here and included Regression.h.

##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       How do you control the maximum wait time?

##########
File path: tests/gold_tests/unit_testing/unit_testing.h
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include <ts/ts.h>
+
+namespace Au_UT
+{
+extern char const Debug_tag[];

Review comment:
       This could be misleading as TSDebug requires a null-terminated C-style string.
   

##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}
+FileDeleter::~FileDeleter()
+{
+  unlink(_pathspec.c_str());
+}
+
+Test::Test(void (*test_func)(InProgress))
+{
+  testList.push_back(test_func);
+}
+
+} // end namespace Au_UT
+
+namespace
+{
+// A copy of this is passed to each test function.  If the test creates any self-deleting objects in the heap,
+// each such object should contain a copy of this object.  When all the copies are destroyed (or reset), the
+// corresponding file will be deleted (and the Au test can detect the deletion).
+//
+InProgress delete_on_completion;
+
+std::atomic<unsigned> lifecycle_event_count;
+
+int
+contFunc(TSCont cont, TSEvent event, void *eventData)
+{
+  ink_release_assert((TS_EVENT_LIFECYCLE_PORTS_READY == event) || (TS_EVENT_LIFECYCLE_TASK_THREADS_READY == event));
+
+  ++lifecycle_event_count;
+
+  ink_release_assert(lifecycle_event_count <= 2);
+
+  if (2 == lifecycle_event_count) {
+    // Run all of the tests in the list.
+    //
+    for (auto fp : testList) {
+      fp(delete_on_completion);
+    }
+
+    // Reset the shared pointer.  From now on, the file to be deleted on completion will only continue to exist
+    // as long as previously-made copies of this object exist.
+    //
+    delete_on_completion.reset();
+
+    TSContDestroy(cont);
+  }
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+// argv[1] - Pathspec of file to delete when all activity triggered by ports ready lifecycle hook completes.
+//
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(Debug_tag, "unit_testing: TSPluginInit()");
+
+  TSReleaseAssert(2 == argc);
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = "unit_testing";
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError("unit_testing: Plugin registration failed");
+
+    return;
+  }
+
+  delete_on_completion.reset(new FileDeleter(argv[1]));

Review comment:
       How is that better?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493069883



##########
File path: tests/gold_tests/unit_testing/unit_testing.h
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include <ts/ts.h>
+
+namespace Au_UT
+{
+extern char const Debug_tag[];

Review comment:
       This could be misleading as TSDebug requires a null-terminated C-style string.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-696796322


   Review hints:
   - The code in PluginVC_UT.cc is an edited version of the regression test code in proxy/PluginVC.cc
   - The code in NetVCTest.h and NetVCTest.cc is an edited version of the code in P_NetVCTest.h and NetVCTest.cc in iocore/net .


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] bryancall commented on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
bryancall commented on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-769448005


   @zwoop Can you please take a look at this?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493015424



##########
File path: iocore/net/P_Net.h
##########
@@ -104,7 +104,6 @@ extern RecRawStatBlock *net_rsb;
 #include "P_UnixPollDescriptor.h"
 #include "P_Socks.h"
 #include "P_CompletionUtil.h"
-#include "P_NetVCTest.h"

Review comment:
       Had to correct many improper dependencies on the fact that P_NetVCTest.h is included here and included Regression.h.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-698554021


   @SolidWallOfCode you may want to look at this as it involves a strategy of moving some unit testing from Catch to Au testing.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras closed pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras closed pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-696796322


   Review hints:
   - The code in PluginVC_UT.cc is an edited version of the regression test code in proxy/PluginVC.cc
   - The code in NetVCTest.h and NetVCTest.cc is an edited version of the code in P_NetVCTest.h and NetVCTest.cc in iocore/net .


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] bneradt commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
bneradt commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493155876



##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}
+FileDeleter::~FileDeleter()
+{
+  unlink(_pathspec.c_str());
+}
+
+Test::Test(void (*test_func)(InProgress))
+{
+  testList.push_back(test_func);
+}
+
+} // end namespace Au_UT
+
+namespace
+{
+// A copy of this is passed to each test function.  If the test creates any self-deleting objects in the heap,
+// each such object should contain a copy of this object.  When all the copies are destroyed (or reset), the
+// corresponding file will be deleted (and the Au test can detect the deletion).
+//
+InProgress delete_on_completion;
+
+std::atomic<unsigned> lifecycle_event_count;
+
+int
+contFunc(TSCont cont, TSEvent event, void *eventData)
+{
+  ink_release_assert((TS_EVENT_LIFECYCLE_PORTS_READY == event) || (TS_EVENT_LIFECYCLE_TASK_THREADS_READY == event));
+
+  ++lifecycle_event_count;
+
+  ink_release_assert(lifecycle_event_count <= 2);
+
+  if (2 == lifecycle_event_count) {
+    // Run all of the tests in the list.
+    //
+    for (auto fp : testList) {
+      fp(delete_on_completion);
+    }
+
+    // Reset the shared pointer.  From now on, the file to be deleted on completion will only continue to exist
+    // as long as previously-made copies of this object exist.
+    //
+    delete_on_completion.reset();
+
+    TSContDestroy(cont);
+  }
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+// argv[1] - Pathspec of file to delete when all activity triggered by ports ready lifecycle hook completes.
+//
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(Debug_tag, "unit_testing: TSPluginInit()");
+
+  TSReleaseAssert(2 == argc);
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = "unit_testing";
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError("unit_testing: Plugin registration failed");
+
+    return;
+  }
+
+  delete_on_completion.reset(new FileDeleter(argv[1]));

Review comment:
       Do you have Effective Modern C++? Item 21, "Prefer std::make_unique and std::make_shared to direct use of new" articulate while it's usually to use make_shared over new. I generally follow that principle.
   
   But it's not a big deal.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-697435337


   [approve ci autest]


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras removed a comment on pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras removed a comment on pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#issuecomment-697435337


   [approve ci autest]


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] bneradt commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
bneradt commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493056684



##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       Can we use the [FileNotExists](https://autestsuite.bitbucket.io/API/when.html#autest.whenitem.filemodified.FileNotExists) When function for this? I think it would look something like:
   
   ```
   ...
   tr.Processes.Default.Command = "echo 'Wait for progress file to be deleted'"
   tr.Processes.Default.Ready = When.FileNotExists(InProgressFilePathspec)
   ...
   ```

##########
File path: tests/gold_tests/unit_testing/unit_testing.h
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include <ts/ts.h>
+
+namespace Au_UT
+{
+extern char const Debug_tag[];

Review comment:
       Can this be a constexpr std::string_view defined in place here?

##########
File path: tests/gold_tests/unit_testing/PluginVC/NetVCTest.cc
##########
@@ -0,0 +1,368 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+ */
+
+/****************************************************************************
+
+   NetVCTest.cc
+
+   Description:
+       Unit test for infrastructure for VConnections implementing the
+         NetVConnection interface
+
+ ****************************************************************************/
+
+#include <P_Net.h>
+
+#include "NetVCTest.h"
+#include "../unit_testing.h"
+
+namespace Au_UT
+{
+// Each test requires two definition entries.  One for the passive
+//   side of the connection and one for the active side
+//
+//  test fields:
+//
+//  name bytes_to_send nbytes_write bytes_to_read nbytes_read write_per timeout read_term write_term
+//
+NVC_test_def netvc_tests_def[] = {
+
+  {"basic", 2000, 2000, 2000, 2000, 50, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"basic", 2000, 2000, 2000, 2000, 50, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"basic2", 10001, 10001, 5001, 5001, 1024, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"basic2", 5001, 5001, 10001, 10001, 1024, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"large", 1000000, 1000000, 500000, 500000, 8192, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"large", 500000, 500000, 1000000, 1000000, 8192, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  // Test large block transfers
+  {"larget", 1000000, 1000000, 500000, 500000, 40000, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"larget", 500000, 500000, 1000000, 1000000, 40000, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"eos", 4000, 4000, 10, 10, 8192, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"eos", 10, 10, 6000, 6000, 8192, 10, VC_EVENT_EOS, VC_EVENT_WRITE_COMPLETE},
+
+  {"werr", 4000, 4000, 10, 10, 129, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_ERROR},
+  {"werr", 10, 10, 10, 10, 129, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"itimeout", 6000, 8000, 10, 10, 512, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_INACTIVITY_TIMEOUT},
+  {"itimeout", 10, 10, 6000, 8000, 512, 20, VC_EVENT_EOS, VC_EVENT_WRITE_COMPLETE},
+
+  // Test the small transfer code one byte at a time
+  {"smallt", 400, 400, 500, 500, 1, 15, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"smallt", 500, 500, 400, 400, 1, 15, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  // The purpose of this test is show that stack can over flow if we move too
+  //   small of blocks between the buffers.  EVENT_NONE is wild card error event

Review comment:
       I think:
   "over flow" -> "overflow" and "wild card" -> "wildcard"

##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}
+FileDeleter::~FileDeleter()
+{
+  unlink(_pathspec.c_str());
+}
+
+Test::Test(void (*test_func)(InProgress))
+{
+  testList.push_back(test_func);
+}
+
+} // end namespace Au_UT
+
+namespace
+{
+// A copy of this is passed to each test function.  If the test creates any self-deleting objects in the heap,
+// each such object should contain a copy of this object.  When all the copies are destroyed (or reset), the
+// corresponding file will be deleted (and the Au test can detect the deletion).
+//
+InProgress delete_on_completion;
+
+std::atomic<unsigned> lifecycle_event_count;
+
+int
+contFunc(TSCont cont, TSEvent event, void *eventData)
+{
+  ink_release_assert((TS_EVENT_LIFECYCLE_PORTS_READY == event) || (TS_EVENT_LIFECYCLE_TASK_THREADS_READY == event));
+
+  ++lifecycle_event_count;
+
+  ink_release_assert(lifecycle_event_count <= 2);
+
+  if (2 == lifecycle_event_count) {
+    // Run all of the tests in the list.
+    //
+    for (auto fp : testList) {
+      fp(delete_on_completion);
+    }
+
+    // Reset the shared pointer.  From now on, the file to be deleted on completion will only continue to exist
+    // as long as previously-made copies of this object exist.
+    //
+    delete_on_completion.reset();
+
+    TSContDestroy(cont);
+  }
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+// argv[1] - Pathspec of file to delete when all activity triggered by ports ready lifecycle hook completes.
+//
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(Debug_tag, "unit_testing: TSPluginInit()");
+
+  TSReleaseAssert(2 == argc);
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = "unit_testing";
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError("unit_testing: Plugin registration failed");
+
+    return;
+  }
+
+  delete_on_completion.reset(new FileDeleter(argv[1]));

Review comment:
       Suggest reassigning via make_shared.

##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}

Review comment:
       Suggest taking a std::string_view.

##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}
+FileDeleter::~FileDeleter()
+{
+  unlink(_pathspec.c_str());
+}
+
+Test::Test(void (*test_func)(InProgress))
+{
+  testList.push_back(test_func);
+}
+
+} // end namespace Au_UT
+
+namespace
+{
+// A copy of this is passed to each test function.  If the test creates any self-deleting objects in the heap,
+// each such object should contain a copy of this object.  When all the copies are destroyed (or reset), the
+// corresponding file will be deleted (and the Au test can detect the deletion).
+//
+InProgress delete_on_completion;
+
+std::atomic<unsigned> lifecycle_event_count;
+
+int
+contFunc(TSCont cont, TSEvent event, void *eventData)
+{
+  ink_release_assert((TS_EVENT_LIFECYCLE_PORTS_READY == event) || (TS_EVENT_LIFECYCLE_TASK_THREADS_READY == event));
+
+  ++lifecycle_event_count;
+
+  ink_release_assert(lifecycle_event_count <= 2);
+
+  if (2 == lifecycle_event_count) {
+    // Run all of the tests in the list.
+    //
+    for (auto fp : testList) {
+      fp(delete_on_completion);
+    }
+
+    // Reset the shared pointer.  From now on, the file to be deleted on completion will only continue to exist
+    // as long as previously-made copies of this object exist.
+    //
+    delete_on_completion.reset();
+
+    TSContDestroy(cont);
+  }
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+// argv[1] - Pathspec of file to delete when all activity triggered by ports ready lifecycle hook completes.
+//
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(Debug_tag, "unit_testing: TSPluginInit()");
+
+  TSReleaseAssert(2 == argc);
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = "unit_testing";
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError("unit_testing: Plugin registration failed");
+
+    return;
+  }
+
+  delete_on_completion.reset(new FileDeleter(argv[1]));

Review comment:
       Do you have Effective Modern C++? Item 21, "Prefer std::make_unique and std::make_shared to direct use of new" articulate while it's usually to use make_shared over new. I generally follow that principle.
   
   But it's not a big deal.

##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       I believe you should be able to use [StartupTimeout](https://autestsuite.bitbucket.io/API/process.html?highlight=timeout#autest.testenities.process.Process.StartupTimeout).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493603660



##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       FileNotExists() seems to always return True.  I am running autest 1.7.3, is this a bug in that version?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] bneradt commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
bneradt commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493056684



##########
File path: tests/gold_tests/unit_testing/unit_testing.test.py
##########
@@ -0,0 +1,60 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you 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.
+
+# Some TS code has very complex dependencies.  This make it impractical to unit test it with Catch, because it's
+# too complicated to link a Catch executable.  Such code should be unit tested in the plugin for this Au test.
+
+import os
+
+
+Test.Summary = '''
+Unit testing for code with complex dependencies.
+'''
+
+ts = Test.MakeATSProcess("ts")
+
+ts.Disk.records_config.update({
+    # NOTE: The PluginVC "overflow" test seems to get into an infinite loop when debug out is enabled.
+    'proxy.config.diags.debug.enabled': 0,
+    'proxy.config.diags.debug.tags': 'pvc|pvc_event|Au_UT',
+})
+
+# File to be deleted when tests are fully completed.
+#
+InProgressFilePathspec = os.path.join(Test.RunDirectory, "in_progress")
+
+Test.PrepareTestPlugin(
+    os.path.join(os.path.join(Test.TestDirectory, ".libs"), "unit_testing.so"), ts,
+    plugin_args=InProgressFilePathspec
+)
+
+# Create file to be deleted when tests are fully completed.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = "touch " + InProgressFilePathspec
+tr.Processes.Default.ReturnCode = 0
+
+# Give tests up to 60 seconds to complete.
+#
+tr = Test.AddTestRun()
+tr.Processes.Default.StartBefore(ts)
+tr.Processes.Default.Command = (
+    "N=60 ; while ((N > 0 )) ; do " +
+    "if [[ ! -f " + InProgressFilePathspec + " ]] ; then exit 0 ; fi ; sleep 1 ; let N=N-1 ; " +
+    "done ; echo 'TIMEOUT' ; exit 1"
+)
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Review comment:
       Can we use the [FileNotExists](https://autestsuite.bitbucket.io/API/when.html#autest.whenitem.filemodified.FileNotExists) When function for this? I think it would look something like:
   
   ```
   ...
   tr.Processes.Default.Command = "echo 'Wait for progress file to be deleted'"
   tr.Processes.Default.Ready = When.FileNotExists(InProgressFilePathspec)
   ...
   ```

##########
File path: tests/gold_tests/unit_testing/unit_testing.h
##########
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <string>
+
+#include <ts/ts.h>
+
+namespace Au_UT
+{
+extern char const Debug_tag[];

Review comment:
       Can this be a constexpr std::string_view defined in place here?

##########
File path: tests/gold_tests/unit_testing/PluginVC/NetVCTest.cc
##########
@@ -0,0 +1,368 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+ */
+
+/****************************************************************************
+
+   NetVCTest.cc
+
+   Description:
+       Unit test for infrastructure for VConnections implementing the
+         NetVConnection interface
+
+ ****************************************************************************/
+
+#include <P_Net.h>
+
+#include "NetVCTest.h"
+#include "../unit_testing.h"
+
+namespace Au_UT
+{
+// Each test requires two definition entries.  One for the passive
+//   side of the connection and one for the active side
+//
+//  test fields:
+//
+//  name bytes_to_send nbytes_write bytes_to_read nbytes_read write_per timeout read_term write_term
+//
+NVC_test_def netvc_tests_def[] = {
+
+  {"basic", 2000, 2000, 2000, 2000, 50, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"basic", 2000, 2000, 2000, 2000, 50, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"basic2", 10001, 10001, 5001, 5001, 1024, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"basic2", 5001, 5001, 10001, 10001, 1024, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"large", 1000000, 1000000, 500000, 500000, 8192, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"large", 500000, 500000, 1000000, 1000000, 8192, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  // Test large block transfers
+  {"larget", 1000000, 1000000, 500000, 500000, 40000, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"larget", 500000, 500000, 1000000, 1000000, 40000, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"eos", 4000, 4000, 10, 10, 8192, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"eos", 10, 10, 6000, 6000, 8192, 10, VC_EVENT_EOS, VC_EVENT_WRITE_COMPLETE},
+
+  {"werr", 4000, 4000, 10, 10, 129, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_ERROR},
+  {"werr", 10, 10, 10, 10, 129, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  {"itimeout", 6000, 8000, 10, 10, 512, 10, VC_EVENT_READ_COMPLETE, VC_EVENT_INACTIVITY_TIMEOUT},
+  {"itimeout", 10, 10, 6000, 8000, 512, 20, VC_EVENT_EOS, VC_EVENT_WRITE_COMPLETE},
+
+  // Test the small transfer code one byte at a time
+  {"smallt", 400, 400, 500, 500, 1, 15, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+  {"smallt", 500, 500, 400, 400, 1, 15, VC_EVENT_READ_COMPLETE, VC_EVENT_WRITE_COMPLETE},
+
+  // The purpose of this test is show that stack can over flow if we move too
+  //   small of blocks between the buffers.  EVENT_NONE is wild card error event

Review comment:
       I think:
   "over flow" -> "overflow" and "wild card" -> "wildcard"

##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}
+FileDeleter::~FileDeleter()
+{
+  unlink(_pathspec.c_str());
+}
+
+Test::Test(void (*test_func)(InProgress))
+{
+  testList.push_back(test_func);
+}
+
+} // end namespace Au_UT
+
+namespace
+{
+// A copy of this is passed to each test function.  If the test creates any self-deleting objects in the heap,
+// each such object should contain a copy of this object.  When all the copies are destroyed (or reset), the
+// corresponding file will be deleted (and the Au test can detect the deletion).
+//
+InProgress delete_on_completion;
+
+std::atomic<unsigned> lifecycle_event_count;
+
+int
+contFunc(TSCont cont, TSEvent event, void *eventData)
+{
+  ink_release_assert((TS_EVENT_LIFECYCLE_PORTS_READY == event) || (TS_EVENT_LIFECYCLE_TASK_THREADS_READY == event));
+
+  ++lifecycle_event_count;
+
+  ink_release_assert(lifecycle_event_count <= 2);
+
+  if (2 == lifecycle_event_count) {
+    // Run all of the tests in the list.
+    //
+    for (auto fp : testList) {
+      fp(delete_on_completion);
+    }
+
+    // Reset the shared pointer.  From now on, the file to be deleted on completion will only continue to exist
+    // as long as previously-made copies of this object exist.
+    //
+    delete_on_completion.reset();
+
+    TSContDestroy(cont);
+  }
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+// argv[1] - Pathspec of file to delete when all activity triggered by ports ready lifecycle hook completes.
+//
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(Debug_tag, "unit_testing: TSPluginInit()");
+
+  TSReleaseAssert(2 == argc);
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = "unit_testing";
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError("unit_testing: Plugin registration failed");
+
+    return;
+  }
+
+  delete_on_completion.reset(new FileDeleter(argv[1]));

Review comment:
       Suggest reassigning via make_shared.

##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}

Review comment:
       Suggest taking a std::string_view.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [trafficserver] ywkaras commented on a change in pull request #7203: Convert PluginVC Regression Test to an Au Test.

Posted by GitBox <gi...@apache.org>.
ywkaras commented on a change in pull request #7203:
URL: https://github.com/apache/trafficserver/pull/7203#discussion_r493070225



##########
File path: tests/gold_tests/unit_testing/unit_testing.cc
##########
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <string>
+#include <deque>
+#include <atomic>
+
+#include <unistd.h>
+
+#include <tscore/ink_assert.h>
+
+#include "unit_testing.h"
+
+namespace
+{
+std::deque<void (*)(InProgress)> testList;
+}
+
+namespace Au_UT
+{
+char const Debug_tag[] = "Au_UT";
+
+FileDeleter::FileDeleter(std::string const &pathspec) : _pathspec(pathspec) {}
+FileDeleter::~FileDeleter()
+{
+  unlink(_pathspec.c_str());
+}
+
+Test::Test(void (*test_func)(InProgress))
+{
+  testList.push_back(test_func);
+}
+
+} // end namespace Au_UT
+
+namespace
+{
+// A copy of this is passed to each test function.  If the test creates any self-deleting objects in the heap,
+// each such object should contain a copy of this object.  When all the copies are destroyed (or reset), the
+// corresponding file will be deleted (and the Au test can detect the deletion).
+//
+InProgress delete_on_completion;
+
+std::atomic<unsigned> lifecycle_event_count;
+
+int
+contFunc(TSCont cont, TSEvent event, void *eventData)
+{
+  ink_release_assert((TS_EVENT_LIFECYCLE_PORTS_READY == event) || (TS_EVENT_LIFECYCLE_TASK_THREADS_READY == event));
+
+  ++lifecycle_event_count;
+
+  ink_release_assert(lifecycle_event_count <= 2);
+
+  if (2 == lifecycle_event_count) {
+    // Run all of the tests in the list.
+    //
+    for (auto fp : testList) {
+      fp(delete_on_completion);
+    }
+
+    // Reset the shared pointer.  From now on, the file to be deleted on completion will only continue to exist
+    // as long as previously-made copies of this object exist.
+    //
+    delete_on_completion.reset();
+
+    TSContDestroy(cont);
+  }
+
+  return 0;
+}
+
+} // end anonymous namespace
+
+// argv[1] - Pathspec of file to delete when all activity triggered by ports ready lifecycle hook completes.
+//
+void
+TSPluginInit(int argc, const char *argv[])
+{
+  TSDebug(Debug_tag, "unit_testing: TSPluginInit()");
+
+  TSReleaseAssert(2 == argc);
+
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = "unit_testing";
+  info.vendor_name   = "Apache Software Foundation";
+  info.support_email = "dev@trafficserver.apache.org";
+
+  if (TSPluginRegister(&info) != TS_SUCCESS) {
+    TSError("unit_testing: Plugin registration failed");
+
+    return;
+  }
+
+  delete_on_completion.reset(new FileDeleter(argv[1]));

Review comment:
       How is that better?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org