Copilot commented on code in PR #13543:
URL: https://github.com/apache/trafficserver/pull/13543#discussion_r3776749531


##########
src/iocore/net/unit_tests/test_NetHandler.cc:
##########
@@ -0,0 +1,43 @@
+/** @file
+
+  Catch based unit tests for NetHandler
+
+  @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.
+ */
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <cstdint>
+#include <set>
+
+#include "iocore/net/NetHandler.h"

Review Comment:
   This test uses `size_t` (line 42) but doesn’t include `<cstddef>`. Adding it 
explicitly avoids depending on transitive includes from Catch2 / STL headers.



##########
src/iocore/net/UnixNet.cc:
##########
@@ -41,20 +41,12 @@ std::atomic<bool> net_memory_throttle = false;
 int               fds_throttle;
 ink_hrtime        last_transient_accept_error;
 
-namespace
-{
-/// Config members that @c NetHandler::configure_per_thread_values reads.
-constexpr unsigned long long PER_THREAD_DEPENDENT_CONFIG{0x3};
-// std::bitset silently discards bits at or above its width, which would drop a
-// member from the set without any diagnostic if Config ever shrinks. The first
-// assertion keeps the shift in the second one well defined.
-static_assert(NetHandler::CONFIG_ITEM_COUNT < std::numeric_limits<unsigned 
long long>::digits);
-static_assert(PER_THREAD_DEPENDENT_CONFIG < (1ULL << 
NetHandler::CONFIG_ITEM_COUNT));
-} // end anonymous namespace
-
 NetHandler::Config                                     
NetHandler::global_config;
 std::bitset<std::numeric_limits<unsigned int>::digits> 
NetHandler::active_thread_types;
-const std::bitset<NetHandler::CONFIG_ITEM_COUNT> 
NetHandler::config_value_affects_per_thread_value{PER_THREAD_DEPENDENT_CONFIG};
+/// The values @c NetHandler::configure_per_thread_values reads.
+const std::bitset<NetHandler::CONFIG_ITEM_COUNT> 
NetHandler::config_value_affects_per_thread_value{
+  (1U << static_cast<unsigned>(NetHandler::Config::Index::MAX_CONNECTIONS_IN)) 
|
+  (1U << static_cast<unsigned>(NetHandler::Config::Index::MAX_REQUESTS_IN))};
 

Review Comment:
   `config_value_affects_per_thread_value` is built via `std::bitset`’s integer 
constructor and `1U << ...` shifts. Without a guard this becomes undefined 
behavior if an index ever reaches 32 (shift on `unsigned`) and it silently 
can’t represent bits above 63 if `CONFIG_ITEM_COUNT` grows beyond 64. Using 
`1ULL` plus a `static_assert` keeps the initialization well-defined.



##########
src/iocore/net/unit_tests/test_NetHandler.cc:
##########
@@ -0,0 +1,43 @@
+/** @file
+
+  Catch based unit tests for NetHandler
+
+  @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.
+ */
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <cstdint>
+#include <set>
+
+#include "iocore/net/NetHandler.h"
+
+// The switch in Config::operator[] is checked for exhaustiveness by the
+// compiler, but not for correctness: a case returning the wrong member still
+// builds. That would make a record update write to the wrong config value.
+TEST_CASE("Every Config index maps to a distinct member", "[net][nethandler]")
+{
+  NetHandler::Config         config;
+  std::set<uint32_t const *> members;
+
+  for (int i = 0; i < NetHandler::CONFIG_ITEM_COUNT; ++i) {
+    members.insert(&config[static_cast<NetHandler::Config::Index>(i)]);
+  }
+  CHECK(members.size() == static_cast<size_t>(NetHandler::CONFIG_ITEM_COUNT));

Review Comment:
   Prefer `std::size_t` over unqualified `size_t` to avoid relying on 
`::size_t` being injected into the global namespace.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to