165b52cdfSJim Walker/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
265b52cdfSJim Walker/*
365b52cdfSJim Walker *     Copyright 2018 Couchbase, Inc
465b52cdfSJim Walker *
565b52cdfSJim Walker *   Licensed under the Apache License, Version 2.0 (the "License");
665b52cdfSJim Walker *   you may not use this file except in compliance with the License.
765b52cdfSJim Walker *   You may obtain a copy of the License at
865b52cdfSJim Walker *
965b52cdfSJim Walker *       http://www.apache.org/licenses/LICENSE-2.0
1065b52cdfSJim Walker *
1165b52cdfSJim Walker *   Unless required by applicable law or agreed to in writing, software
1265b52cdfSJim Walker *   distributed under the License is distributed on an "AS IS" BASIS,
1365b52cdfSJim Walker *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1465b52cdfSJim Walker *   See the License for the specific language governing permissions and
1565b52cdfSJim Walker *   limitations under the License.
1665b52cdfSJim Walker */
1765b52cdfSJim Walker
1865b52cdfSJim Walker#include <platform/corestore.h>
1965b52cdfSJim Walker
2065b52cdfSJim Walker#include <gtest/gtest.h>
2165b52cdfSJim Walker
2265b52cdfSJim Walker#include <atomic>
2365b52cdfSJim Walker#include <iostream>
2465b52cdfSJim Walker
2565b52cdfSJim Walkerclass CoreStoreTest : public ::testing::Test {
2665b52cdfSJim Walkerpublic:
2765b52cdfSJim Walker};
2865b52cdfSJim Walker
2965b52cdfSJim WalkerTEST_F(CoreStoreTest, test) {
3065b52cdfSJim Walker    CoreStore<std::atomic<uint32_t>> corestore;
3165b52cdfSJim Walker
3265b52cdfSJim Walker    std::cout << corestore.size() << std::endl;
3365b52cdfSJim Walker
341ebd7828SDave Rigby    size_t count = 0;
3565b52cdfSJim Walker    for (auto& e : corestore) {
361ebd7828SDave Rigby        EXPECT_EQ(0u, e.load());
3765b52cdfSJim Walker        count++;
3865b52cdfSJim Walker    }
3965b52cdfSJim Walker    EXPECT_EQ(corestore.size(), count);
4065b52cdfSJim Walker    corestore.get()++;
4165b52cdfSJim Walker    // Can't guarantee the next get would hit the same element... so check all
4265b52cdfSJim Walker    count = 0;
4365b52cdfSJim Walker    for (auto& e : corestore) {
4465b52cdfSJim Walker        if (e.load() != 0) {
4565b52cdfSJim Walker            count++;
4665b52cdfSJim Walker        }
4765b52cdfSJim Walker    }
4865b52cdfSJim Walker
4965b52cdfSJim Walker    // Expected on core slot to be non-zero
501ebd7828SDave Rigby    EXPECT_EQ(1u, count);
511ebd7828SDave Rigby}
52