mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
apps/testing:Add c++ STL code size test case.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
This commit is contained in:
parent
d91e3db9fd
commit
e50627ecd6
29 changed files with 1654 additions and 0 deletions
37
testing/cxxsize/CMakeLists.txt
Normal file
37
testing/cxxsize/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# ##############################################################################
|
||||
# apps/testing/cxxsize/CMakeLists.txt
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# ##############################################################################
|
||||
|
||||
if(CONFIG_TESTING_CXXSIZE)
|
||||
file(GLOB SOURCES "*.cxx")
|
||||
|
||||
foreach(src ${SOURCES})
|
||||
get_filename_component(name ${src} NAME_WE)
|
||||
nuttx_add_application(
|
||||
NAME
|
||||
${name}
|
||||
STACKSIZE
|
||||
${CONFIG_DEFAULT_TASK_STACKSIZE}
|
||||
MODULE
|
||||
${CONFIG_TESTING_CXXSIZE}
|
||||
SRCS
|
||||
${src})
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
9
testing/cxxsize/Kconfig
Normal file
9
testing/cxxsize/Kconfig
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config TESTING_CXXSIZE
|
||||
tristate "Test c++ code size program"
|
||||
default n
|
||||
depends on HAVE_CXX
|
||||
23
testing/cxxsize/Make.defs
Normal file
23
testing/cxxsize/Make.defs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
############################################################################
|
||||
# apps/testing/cxxtest/Make.defs
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_TESTING_CXXSIZE),)
|
||||
CONFIGURED_APPS += $(APPDIR)/testing/cxxsize
|
||||
endif
|
||||
32
testing/cxxsize/Makefile
Normal file
32
testing/cxxsize/Makefile
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
############################################################################
|
||||
# apps/testing/cxxtest/Makefile
|
||||
#
|
||||
# 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 $(APPDIR)/Make.defs
|
||||
|
||||
# CXX code test program
|
||||
|
||||
MAINSRC := $(wildcard *.cxx)
|
||||
PROGNAME := $(patsubst %.cxx,%, $(wildcard *.cxx))
|
||||
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_TESTING_CXXSIZE)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
109
testing/cxxsize/README.md
Normal file
109
testing/cxxsize/README.md
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
# C++ Standard Library Code Size Testing Program
|
||||
|
||||
## Introduction
|
||||
|
||||
This project provides a testing program designed to measure the code size of each class in the C++ Standard Library. Understanding the code size of various classes can help developers optimize their usage of the standard library and make informed design decisions in their applications. This program aims to provide clear insights into how much memory each component of the standard library consumes, categorized into text, data, BSS, and overall size (DEC).
|
||||
|
||||
## Purpose
|
||||
|
||||
The primary goals of this project are to:
|
||||
- **Analyze the memory consumption** of standard library components.
|
||||
- **Identify potential areas for optimization** in applications that utilize these components.
|
||||
- **Aid developers** in making better decisions regarding the use of the C++ Standard Library depending on their application’s constraints.
|
||||
|
||||
## Testing Platform
|
||||
This program has been tested on the x4b/release branch.
|
||||
|
||||
## C++ Compilation Configurations
|
||||
|
||||
- `CONFIG_HAVE_CXX`
|
||||
- `CONFIG_HAVE_CXXINITIALIZE`
|
||||
- `CONFIG_LIBCXX`
|
||||
- `CONFIG_LIBSUPCXX`
|
||||
|
||||
## Optimization Configurations
|
||||
|
||||
- `CONFIG_DEBUG_OPTLEVEL="-Os"`
|
||||
- `CONFIG_LTO_FULL`
|
||||
- `-ffunction-section`
|
||||
- `-fdata-section`
|
||||
|
||||
## Component-Specific Configurations
|
||||
|
||||
- **`iostream`**: enable `CONFIG_LIBC_LOCALE`.
|
||||
- **`exception`**: enable `CONFIG_CXX_EXCEPTION`.
|
||||
- **`rtti`**: enable `CONFIG_CXX_RTTI`.
|
||||
|
||||
## Compilation Instructions
|
||||
|
||||
To compile the code size testing program, use the following command:
|
||||
|
||||
```bash
|
||||
./build.sh qemu-armv7a:nsh -j
|
||||
```
|
||||
|
||||
## Code Size Breakdown
|
||||
|
||||
The following table summarizes the code size measurements for different components in the C++ Standard Library. The sizes are measured in bytes and broken down into the following categories:
|
||||
|
||||
- **Text**: Size of the code segment containing executable instructions.
|
||||
- **Data**: Size of initialized global and static variables.
|
||||
- **BSS**: Size of uninitialized global and static variables.
|
||||
- **DEC**: Total size in bytes (sum of Text, Data, and BSS).
|
||||
|
||||
### Output Examples
|
||||
|
||||
#### Without C++ Config
|
||||
|
||||
```
|
||||
text data bss dec hex filename
|
||||
204388 300 9728 214416 34590 nuttx/nuttx
|
||||
```
|
||||
|
||||
#### Only Basic C++ Configurations
|
||||
|
||||
```
|
||||
text data bss dec hex filename
|
||||
208100 300 9856 218256 35490 nuttx/nuttx
|
||||
```
|
||||
|
||||
#### Compiling an Empty main Function with Basic C++ Configurations
|
||||
|
||||
```
|
||||
text data bss dec hex filename
|
||||
208132 300 9856 218288 354b0 nuttx/nuttx
|
||||
```
|
||||
|
||||
### Code Size Measurements
|
||||
|
||||
| **Component** | **Text** | **Data** | **BSS** | **DEC** |
|
||||
| ---------------------|---------|---------|---------|--------|
|
||||
| basic c++ | 3712 | 0 | 128 | 3840 |
|
||||
| array | 32 | 0 | 0 | 32 |
|
||||
| condition_variable | 584 | 8 | 16 | 608 |
|
||||
| deque | 41196 | 300 | 40 | 41544 |
|
||||
| exception | 32 | 0 | 32 | 32 |
|
||||
| forward_list | 41164 | 308 | 40 | 41512 |
|
||||
| future | 43504 | 356 | 112 | 43972 |
|
||||
| iostream | 148004 | 404 | 3160 | 151568 |
|
||||
| list | 41516 | 308 | 40 | 41864 |
|
||||
| map | 45252 | 308 | 40 | 45600 |
|
||||
| multiset | 44676 | 308 | 40 | 45024 |
|
||||
| mutex | 552 | 8 | 16 | 576 |
|
||||
| rtti | 41420 | 308 | 40 | 41768 |
|
||||
| semaphore | 1352 | 8 | 16488 | 17808 |
|
||||
| set | 44644 | 308 | 40 | 44992 |
|
||||
| shared_ptr | 43204 | 308 | 40 | 41712 |
|
||||
| string | 42044 | 308 | 40 | 42392 |
|
||||
| string_view | 448 | 0 | 0 | 448 |
|
||||
| thread | 41956 | 356 | 12 | 42424 |
|
||||
| unordered_map | 47668 | 308 | 40 | 48016 |
|
||||
| unordered_multimap | 46868 | 308 | 40 | 47216 |
|
||||
| unordered_multiset | 46836 | 308 | 40 | 47184 |
|
||||
| unordered_set | 46452 | 308 | 40 | 46800 |
|
||||
| vector | 41444 | 308 | 40 | 41792 |
|
||||
| weak_ptr | 43460 | 308 | 40 | 41936 |
|
||||
|
||||
## Conclusion
|
||||
|
||||
By analyzing the code size of each component in the C++ Standard Library, developers can better understand the memory implications of their usage of these classes. The details provided in this README serve as a reference point for optimizing application performance and making educated design choices. We hope you find this information valuable as you work with the C++ Standard Library.
|
||||
51
testing/cxxsize/array.cxx
Normal file
51
testing/cxxsize/array.cxx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/array.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <array>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: array_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::array<int, 3> arr;
|
||||
|
||||
arr = { 1, 2, 3 };
|
||||
arr[1] = 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
61
testing/cxxsize/condition_variable.cxx
Normal file
61
testing/cxxsize/condition_variable.cxx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/condition_variable.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: condition_variable_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
bool ready = false;
|
||||
std::condition_variable cv;
|
||||
std::mutex mtx;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
ready = true;
|
||||
}
|
||||
|
||||
cv.notify_one();
|
||||
|
||||
std::unique_lock<std::mutex> lock(mtx);
|
||||
cv.wait(lock, [&ready] { return ready; });
|
||||
|
||||
return 0;
|
||||
}
|
||||
60
testing/cxxsize/deque.cxx
Normal file
60
testing/cxxsize/deque.cxx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/deque.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <deque>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: deque_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::deque<int> deq;
|
||||
|
||||
deq.push_back(1);
|
||||
deq.push_back(2);
|
||||
deq.pop_back();
|
||||
|
||||
deq.push_front(3);
|
||||
deq.pop_front();
|
||||
|
||||
deq.insert(deq.begin(), 4);
|
||||
deq.erase(deq.begin());
|
||||
|
||||
deq.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
62
testing/cxxsize/exception.cxx
Normal file
62
testing/cxxsize/exception.cxx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/exception.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#ifdef CONFIG_CXX_EXCEPTION
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: exception_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef CONFIG_CXX_EXCEPTION
|
||||
try
|
||||
{
|
||||
throw std::runtime_error("runtime error");
|
||||
}
|
||||
catch (std::runtime_error &e)
|
||||
{
|
||||
if (e.what())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
58
testing/cxxsize/forward_list.cxx
Normal file
58
testing/cxxsize/forward_list.cxx
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/forward_list.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: forward_list_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::forward_list<int> l;
|
||||
|
||||
l.push_front(1);
|
||||
l.push_front(2);
|
||||
l.push_front(3);
|
||||
l.pop_front();
|
||||
|
||||
l.insert_after(l.begin(), 4);
|
||||
l.erase_after(l.begin());
|
||||
|
||||
l.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
53
testing/cxxsize/future.cxx
Normal file
53
testing/cxxsize/future.cxx
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/future.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <future>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: future_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::future<int> f = std::async(std::launch::async, []() { return 42; });
|
||||
|
||||
if (f.get())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
testing/cxxsize/iostream.cxx
Normal file
56
testing/cxxsize/iostream.cxx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/iostream.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: iostream_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
int num;
|
||||
|
||||
std::cout << "Enter:";
|
||||
std::cin >> num;
|
||||
|
||||
if (std::cin.fail())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
60
testing/cxxsize/list.cxx
Normal file
60
testing/cxxsize/list.cxx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/list.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <list>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: list_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::list<int> l;
|
||||
|
||||
l.push_back(1);
|
||||
l.push_back(2);
|
||||
l.pop_back();
|
||||
|
||||
l.push_front(3);
|
||||
l.pop_front();
|
||||
|
||||
l.insert(l.begin(), 4);
|
||||
l.erase(l.begin());
|
||||
|
||||
l.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
testing/cxxsize/map.cxx
Normal file
64
testing/cxxsize/map.cxx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/map.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <map>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: map_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::map<int, int> m;
|
||||
|
||||
m = {{ 1, 1 }, { 2, 2 }};
|
||||
m[3] = 3;
|
||||
|
||||
if (m.find(1) != m.end())
|
||||
{
|
||||
m.erase(1);
|
||||
}
|
||||
|
||||
while (!m.empty())
|
||||
{
|
||||
m.erase(m.begin());
|
||||
}
|
||||
|
||||
m.insert({4, 4});
|
||||
m.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
testing/cxxsize/multiset.cxx
Normal file
63
testing/cxxsize/multiset.cxx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/multiset.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <set>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: multiset_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::multiset<int> s;
|
||||
|
||||
s = { 1, 2, 2 };
|
||||
|
||||
if (s.find(1) != s.end())
|
||||
{
|
||||
s.erase(1);
|
||||
}
|
||||
|
||||
while (!s.empty())
|
||||
{
|
||||
s.erase(s.begin());
|
||||
}
|
||||
|
||||
s.insert(4);
|
||||
s.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
54
testing/cxxsize/mutex.cxx
Normal file
54
testing/cxxsize/mutex.cxx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/mutex.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <mutex>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: set_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::mutex mtx;
|
||||
|
||||
mtx.lock();
|
||||
mtx.unlock();
|
||||
|
||||
mtx.try_lock();
|
||||
mtx.unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
66
testing/cxxsize/rtti.cxx
Normal file
66
testing/cxxsize/rtti.cxx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/rtti.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
class Base
|
||||
{
|
||||
public:
|
||||
virtual ~Base() {}
|
||||
};
|
||||
|
||||
class Derived : public Base {};
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: rtti_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
Base* basePtr = new Derived();
|
||||
Derived* derivedPtr = dynamic_cast<Derived*>(basePtr);
|
||||
|
||||
if (derivedPtr)
|
||||
{
|
||||
delete basePtr;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete basePtr;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
51
testing/cxxsize/semaphore.cxx
Normal file
51
testing/cxxsize/semaphore.cxx
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/semaphore.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <semaphore>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: semaphore_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::counting_semaphore sem(0);
|
||||
|
||||
sem.release();
|
||||
sem.acquire();
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
testing/cxxsize/set.cxx
Normal file
63
testing/cxxsize/set.cxx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/set.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <set>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: set_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::set<int> s;
|
||||
|
||||
s = { 1, 2, 3 };
|
||||
|
||||
if (s.find(1) != s.end())
|
||||
{
|
||||
s.erase(1);
|
||||
}
|
||||
|
||||
while (!s.empty())
|
||||
{
|
||||
s.erase(s.begin());
|
||||
}
|
||||
|
||||
s.insert(4);
|
||||
s.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
60
testing/cxxsize/shared_ptr.cxx
Normal file
60
testing/cxxsize/shared_ptr.cxx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/shared_ptr.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <memory>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: shared_ptr_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::shared_ptr<int> ptr(new int(10));
|
||||
|
||||
if(ptr == nullptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
ptr.reset();
|
||||
|
||||
if (ptr.use_count())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
64
testing/cxxsize/string.cxx
Normal file
64
testing/cxxsize/string.cxx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/string.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <string>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: string_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::string str = "hello world";
|
||||
|
||||
str.push_back(' ');
|
||||
str.pop_back();
|
||||
|
||||
if (str.find('h'))
|
||||
{
|
||||
str.erase(2, 3);
|
||||
}
|
||||
|
||||
while (!str.empty())
|
||||
{
|
||||
str.erase(str.begin());
|
||||
}
|
||||
|
||||
str.append("world");
|
||||
str.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
testing/cxxsize/string_view.cxx
Normal file
56
testing/cxxsize/string_view.cxx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/string_view.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: string_view_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
char str[] = "hello world";
|
||||
std::string_view sv = str;
|
||||
|
||||
size_t pos = sv.find("world");
|
||||
if (pos != std::string_view::npos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
61
testing/cxxsize/thread.cxx
Normal file
61
testing/cxxsize/thread.cxx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/thread.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <thread>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: thread_function
|
||||
//***************************************************************************/
|
||||
|
||||
void thread_function()
|
||||
{
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Name: thread_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::thread threads(thread_function);
|
||||
|
||||
if (threads.joinable())
|
||||
{
|
||||
threads.join();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
65
testing/cxxsize/unordered_map.cxx
Normal file
65
testing/cxxsize/unordered_map.cxx
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/unordered_map.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: unordered_map_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::unordered_map<int, int> m;
|
||||
|
||||
m = {{ 1, 1 }, { 2, 2 }};
|
||||
m[3] = 3;
|
||||
|
||||
if (m.find(1) != m.end())
|
||||
{
|
||||
m.erase(1);
|
||||
}
|
||||
|
||||
while (!m.empty())
|
||||
{
|
||||
m.erase(m.begin());
|
||||
}
|
||||
|
||||
m.insert({4, 4});
|
||||
m.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
63
testing/cxxsize/unordered_multimap.cxx
Normal file
63
testing/cxxsize/unordered_multimap.cxx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/unordered_multimap.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: unordered_multimap_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::unordered_multimap<int, int> m;
|
||||
|
||||
m = {{ 1, 1 }, { 2, 2 }, { 2, 3 }};
|
||||
|
||||
if (m.find(1) != m.end())
|
||||
{
|
||||
m.erase(1);
|
||||
}
|
||||
|
||||
while (!m.empty())
|
||||
{
|
||||
m.erase(m.begin());
|
||||
}
|
||||
|
||||
m.insert({4, 4});
|
||||
m.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
testing/cxxsize/unordered_multiset.cxx
Normal file
63
testing/cxxsize/unordered_multiset.cxx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/unordered_multiset.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: unordered_multiset_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::unordered_multiset<int> s;
|
||||
|
||||
s = { 1, 2, 2 };
|
||||
|
||||
if (s.find(1) != s.end())
|
||||
{
|
||||
s.erase(1);
|
||||
}
|
||||
|
||||
while (!s.empty())
|
||||
{
|
||||
s.erase(s.begin());
|
||||
}
|
||||
|
||||
s.insert(3);
|
||||
s.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
63
testing/cxxsize/unordered_set.cxx
Normal file
63
testing/cxxsize/unordered_set.cxx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/unordered_set.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: unordered_set_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::unordered_set<int> s;
|
||||
|
||||
s = { 1, 2, 3 };
|
||||
|
||||
if (s.find(1) != s.end())
|
||||
{
|
||||
s.erase(1);
|
||||
}
|
||||
|
||||
while (!s.empty())
|
||||
{
|
||||
s.erase(s.begin());
|
||||
}
|
||||
|
||||
s.insert(4);
|
||||
s.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
59
testing/cxxsize/vector.cxx
Normal file
59
testing/cxxsize/vector.cxx
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/vector.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <vector>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: vector_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::vector<int> vec;
|
||||
|
||||
vec.push_back(1);
|
||||
vec.push_back(2);
|
||||
vec.push_back(3);
|
||||
|
||||
vec.pop_back();
|
||||
|
||||
vec.insert(vec.begin(), 4);
|
||||
vec.erase(vec.begin());
|
||||
|
||||
vec.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
68
testing/cxxsize/weak_ptr.cxx
Normal file
68
testing/cxxsize/weak_ptr.cxx
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
//***************************************************************************
|
||||
// apps/testing/cxxsize/weak_ptr.cxx
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <memory>
|
||||
|
||||
//***************************************************************************
|
||||
// Private Classes
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Private Data
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Public Functions
|
||||
//***************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
// Name: weak_ptr_main
|
||||
//***************************************************************************/
|
||||
|
||||
extern "C" int main(int argc, FAR char *argv[])
|
||||
{
|
||||
std::weak_ptr<int> weak_ptr;
|
||||
std::shared_ptr<int> shared_ptr(new int(10));
|
||||
|
||||
weak_ptr = shared_ptr;
|
||||
|
||||
if (weak_ptr.expired())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (weak_ptr.lock() != shared_ptr)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
shared_ptr.reset();
|
||||
|
||||
if (weak_ptr.use_count())
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue