VSCode_CMake_GoogleTest

重點:

下面這兩行要放在最外面的 CMakeLists.txt 中,這樣才能在build資料夾啟動ctest

1
2
include(CTest)
enable_testing()

讓VSCode的Ctest可以下中斷點

參考:
https://stackoverflow.com/a/76447033/22299707

https://github.com/microsoft/vscode-cmake-tools/blob/defc0b5369c64467c3466b1cee3faba9f9633a6a/docs/debug-launch.md#debugging-tests

launch.json

1
2
3
4
5
6
7
8
9
{
"name": "(ctest) Launch",
"type": "cppdbg",
"cwd": "${cmake.testWorkingDirectory}",
"request": "launch",
"program": "${cmake.testProgram}",
"args": [ "${cmake.testArgs}" ],
// other options...
}

參考:
https://github.com/esweet431/box2d-lite/blob/vs-launch/CMakePresets.json

cmake google test配置

範例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
find_package(Threads REQUIRED)


include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 52eb8108c5bdec04579160ae17225d66034bd723 # release-1.17.0
)
FetchContent_MakeAvailable(googletest)
enable_testing()

# Create a libgmock target to be used as a dependency by test programs

add_subdirectory(testplate)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
include(GoogleTest)
file(GLOB SRCS *.cpp)
add_executable(testplate ${SRCS})


target_link_libraries(testplate
gtest_main
libtestplate
)

gtest_add_tests(TARGET testplate
TEST_SUFFIX .noArgs
TEST_LIST noArgsTests
)

#gtest_add_tests(TARGET testplate
# EXTRA_ARGS --someArg someValue
# TEST_SUFFIX .withArgs
# TEST_LIST withArgsTests
#)

set_tests_properties(${noArgsTests} PROPERTIES TIMEOUT 10)
#set_tests_properties(${withArgsTests} PROPERTIES TIMEOUT 20)

參考:
https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package

https://cmake.org/cmake/help/v3.31/module/GoogleTest.html#command:gtest_add_tests

Ubuntu加入WindowsAD

查詢AD server
文件SSSD
https://documentation.ubuntu.com/server/how-to/sssd/with-active-directory/#sssd-with-active-directory

echo %logonserver%
nslookup

範例:
Microsoft Windows [Version 10.0.19045.5011]
(c) Microsoft Corporation. All rights reserved.

C:\Users\2005013>echo %logonserver%
\IEDC022

C:\Users\2005013>nslookup \IEDC022
Server: DNS221.iead.local
Address: 192.168.16.44

Name: IEDC022.iead.local
Address: 192.168.16.32

C:\Users\2005013>

確保 DNS 配置正確

將 AD 的 DNS 伺服器地址添加到 nameserver,例如:

1
2
nameserver <AD_DNS_SERVER_IP>
search <AD_DOMAIN>

範例
nameserver 192.168.11.32
search iiiid.local

GPT

GitHub Copilot: 在你的情境下,使用 SSSD 整合 Ubuntu Server 與 Windows Active Directory (AD) 是最適合的選擇。SSSD 提供了與 AD 的良好整合,並且支援 Linux 系統的身份驗證和授權,讓擁有 AD 帳號的用戶可以登入 Ubuntu Server。


為什麼選擇 SSSD?

  1. 跨平台支援:SSSD 是 Linux 上的身份驗證解決方案,專為與 AD 整合設計。
  2. 簡化管理:SSSD 支援 Kerberos 和 LDAP,能直接與 AD 通信,並且可以緩存身份驗證數據,減少對 AD 的依賴。
  3. 靈活性:除了身份驗證,SSSD 還支援基於 AD 群組的授權控制。
  4. 穩定性:SSSD 是 Ubuntu 官方推薦的解決方案,並且有良好的社群支持。

實現步驟

以下是將 Ubuntu Server 加入 Windows AD 並允許 AD 用戶登入的基本步驟:

1. 安裝必要的套件

在 Ubuntu Server 上安裝 SSSD 和相關工具:

1
2
sudo apt update
sudo apt install sssd-ad sssd-tools realmd adcli krb5-user packagekit

2. 確保 DNS 配置正確

AD 的身份驗證依賴正確的 DNS 設定,請確保 Ubuntu Server 能解析 AD 網域名稱:

1
sudo nano /etc/resolv.conf

將 AD 的 DNS 伺服器地址添加到 nameserver,例如:

1
2
nameserver <AD_DNS_SERVER_IP>
search <AD_DOMAIN>

3. 加入 AD 網域

使用 realm 工具將 Ubuntu Server 加入 AD 網域:

1
sudo realm join --user=<AD_ADMIN_USERNAME> <AD_DOMAIN>

系統會提示輸入 AD 管理員的密碼,成功後會自動配置 SSSD。

4. 驗證網域加入狀態

確認 Ubuntu Server 已成功加入 AD:

1
realm list

你應該能看到 AD 網域的相關資訊。

5. 配置 SSSD

檢查或修改 SSSD 配置檔案 /etc/sssd/sssd.conf,確保內容類似以下:

1
2
3
4
5
6
7
8
9
[sssd]
services = nss, pam
domains = <AD_DOMAIN>

[domain/<AD_DOMAIN>]
id_provider = ad
access_provider = ad
override_homedir = /home/%d/%u
default_shell = /bin/bash

保存後,重啟 SSSD:

1
sudo systemctl restart sssd

6. 測試 AD 用戶登入

嘗試使用 AD 用戶登入 Ubuntu Server:

1
ssh <AD_USERNAME>@<UBUNTU_SERVER_IP>

如果配置正確,AD 用戶應該能成功登入。

7. 可選:限制登入權限

如果你希望只允許特定 AD 群組的用戶登入,可以在 /etc/sssd/sssd.conf 中添加:

1
2
access_provider = ad
ad_access_filter = (memberOf=CN=<GROUP_NAME>,OU=<OU_NAME>,DC=<DOMAIN>,DC=<COM>)

重啟 SSSD 後,只有屬於該群組的用戶才能登入。


結論

使用 SSSD 是將 Ubuntu Server 加入 Windows AD 的最佳方式,因為它提供了穩定、高效且靈活的身份驗證解決方案。完成上述配置後,AD 用戶即可使用其帳號登入 Ubuntu Server,並且可以根據需求進一步限制登入權限。

參考:

https://poweradm.com/join-ubuntu-debian-active-directory-domain/

使用gst-shark

安裝

git clone https://github.com/RidgeRun/gst-shark/
apt install octave epstool babeltrace gtk-doc-tools
apt install graphviz libgraphviz-dev

編譯

sudo apt install python3 python3-pip ninja-build
pip3 install –user meson
sudo cp ~/.local/bin/meson /usr/bin/meson

meson builddir –prefix /usr/
ninja -C builddir

安裝

ninja install -C builddir

如果有更動gst-shark的程式碼,則需要重新編譯安裝

ninja -C builddir
ninja install -C builddir

在deepstream使用gst-shark的時候會需要修改以下程式碼並且重新編譯,以免出錯
gst_shark_tracer_hook_pad_push_pre,要檢查GST_OBJECT_PARENT的結果是不是NULL,是就return,修改如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* My hooks */
static void
gst_shark_tracer_hook_pad_push_pre (GObject * object, GstClockTime ts,
GstPad * pad, GstBuffer * buffer)
{
GstSharkTracer *self = GST_SHARK_TRACER (object);
GstSharkTracerPrivate *priv = GST_SHARK_TRACER_PRIVATE (self);
GCallback hook;
const gchar *elname;

GstObject* gst_obj = GST_OBJECT_PARENT (pad);
if (gst_obj == NULL){
return;
}
elname = GST_OBJECT_NAME (gst_obj);
if (FALSE == gst_shark_tracer_element_is_filtered (self, elname)) {
return;
}

hook = g_hash_table_lookup (priv->hooks, "pad-push-pre");
g_return_if_fail (hook);

((void (*)(GObject *, GstClockTime, GstPad *, GstBuffer *)) hook) (object, ts,
pad, buffer);
}

使用

export GST_SHARK_LOCATION=/root/apps/iisi-ds64/iisi-ds63/my_exp/shark
export GST_DEBUG=”GST_TRACER:7”
export GST_TRACERS=”queuelevel”

執行deepstream,並且用q結束程式,確認shark底下的metadata有資料

下面是產生圖片的方式

cd gst-shark/scripts/graphics

Display the plot on the screen

./gstshark-plot /root/apps/iisi-ds64/iisi-ds63/my_exp/shark -p

Save the plot to a PDF

./gstshark-plot /root/apps/iisi-ds64/iisi-ds63/my_exp/shark -s pdf

Save the plot to a PNG

./gstshark-plot /root/apps/iisi-ds64/iisi-ds63/my_exp/shark -s png

gstreamer使用gdb的方法

git clone https://gitlab.freedesktop.org/gstreamer/gstreamer.git
cd gstreamer/
git checkout 1.20.3

pip3 install –user meson

meson setup builddir

ninja -C builddir

測試gst環境成功
https://www.collabora.com/news-and-blog/blog/2020/03/19/getting-started-with-gstreamer-gst-build/
1.在程式subprojects/gst-plugins-base/gst/videotestsrc/gstvideotestsrc.c中加料
在gst_video_test_src_start()中加上,故意讓程式報錯跳出

1
GST_ERROR_OBJECT (src, "Starting to debug videotestsrc, is there an error ?");

2.ninja -C build重新編譯程式,可以注意到這次編譯只會編譯被更新的檔案
3.執行GST_DEBUG=videotestsrc:1 gst-launch-1.0 videotestsrc num-buffers=1 ! fakevideosink,並出現錯誤,表示測試成功

1
2
3
4
5
6
7
8
9
10
11
12
Setting pipeline to PAUSED ...
0:00:00.225273663 21743 0x565528ab7100 ERROR videotestsrc gstvideotestsrc.c:1216:gst_video_test_src_start: Starting to debug videotestsrc, is there an error ?
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
Got EOS from element "pipeline0".
Execution ended after 0:00:00.033464391
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ..

使用gst環境(類似python的venv)
python3 gst-env.py
以下連結說明有更新的環境變數
https://gstreamer.freedesktop.org/documentation/installing/building-from-source-using-meson.html#how-does-it-work

此時許多環境變數被自動設置,包含pkg-config也被設置,可以用pkg-config –cflags gstreamer-1.0檢查gstreamer的路徑,如此一來讓cmake編譯也可以連結到自行編譯的程式,並且包含gdb下中斷點需要的資訊

把deepstream的gst-plugin的變數加進來,這樣才找的到deepstream的plugin
export GST_PLUGIN_PATH=/opt/nvidia/deepstream/deepstream/lib/gst-plugins:$GST_PLUGIN_PATH

gdb下中斷點
gst_element_factory_make

vscode要在debug的那一個terimal執行gst-env.py才能讓中斷點停在gstreamer的程式上面

IPMI

Windows

ipmiutil
https://ipmiutil.sourceforge.net/

查看BMC IP

1
./ipmiutil.exe lan -r  

設定BMC IP

1
./ipmiutil.exe lan -e -I 192.168.1.100 -S 255.255.255.0 -G 192.168.1.1

Linux

ipmitool
安裝:

1
sudo apt-get install ipmitool

修改BMC IP

1
ipmitool lan set 1 ipaddr

調整Supermicro X12主機板風扇轉速

1
2
3
4
# 調整為全速模式
sudo ipmitool raw 0x30 0x45 0x01 0x01
#調整風扇轉速為30%
sudo ipmitool raw 0x30 0x70 0x66 0x01 0x00 0x30

要在 Supermicro X12 主機板上使用 ipmitool 調整風扇轉速,您可以按照以下步驟進行:

  1. 安裝 ipmitool:
    在您的管理主機上,確保已安裝 ipmitool。在基於 Debian 的系統上,您可以使用以下命令安裝:

    1
    sudo apt-get install ipmitool

    在 CentOS 系統上,則使用:

    1
    yum install ipmitool
  2. 設置風扇控制模式為手動:
    默認情況下,主機板可能處於自動風扇控制模式。為了手動調整風扇轉速,您需要將風扇模式設置為全速(Full Speed)模式,這樣可以防止自動調節覆蓋您的手動設置。使用以下命令:

    1
    ipmitool -H <IPMI_IP地址> -U <用戶名> -P <密碼> raw 0x30 0x45 0x01 0x01

    其中,<IPMI_IP地址><用戶名><密碼> 分別替換為您的 IPMI 接口的實際 IP 地址、用戶名和密碼。此命令將風扇模式設置為全速運行。 citeturn0search8

  3. 手動設置風扇轉速:
    您可以使用以下命令手動設置風扇轉速:

    1
    ipmitool -H <IPMI_IP地址> -U <用戶名> -P <密碼> raw 0x30 0x70 0x66 0x01 <區域> <轉速百分比>

    其中,<區域> 參數決定了調整哪個風扇區域的轉速:

    • 0x00:系統區域風扇(通常為 CPU、GPU 等核心部件的風扇),對應風扇編號為 FAN1、FAN2 等。
    • 0x01:周邊設備區域風扇(通常為磁盤等外圍設備的風扇),對應風扇編號為 FANA、FANB 等。

    <轉速百分比> 以十六進制表示風扇轉速的百分比,範圍從 0x01(1%)到 0x64(100%)。例如,設置系統區域風扇轉速為 36%(即 0x24):

    1
    ipmitool -H <IPMI_IP地址> -U <用戶名> -P <密碼> raw 0x30 0x70 0x66 0x01 0x00 0x24

    請根據您的實際需求調整風扇轉速百分比。 citeturn0search8

  4. 調整風扇轉速閾值(可選):
    如果您發現風扇轉速不穩定,可能是因為風扇轉速低於主機板設置的下限閾值,導致風扇強制以高轉速運行。您可以使用以下命令調整風扇的下限閾值:

    1
    ipmitool -H <IPMI_IP地址> -U <用戶名> -P <密碼> sensor thresh <風扇編號> lower <LNC> <LC> <LNR>

    其中,<風扇編號> 為您要調整的風扇(如 FAN1),<LNC><LC><LNR> 分別為下限非臨界值、下限臨界值和下限不可恢復值。例如,將 FAN1 的下限閾值設置為 100:

    1
    ipmitool -H <IPMI_IP地址> -U <用戶名> -P <密碼> sensor thresh FAN1 lower 100 100 100

    這樣可以防止風扇因低於閾值而導致的不穩定運行。 citeturn0search0

注意事項:

  • 在進行上述操作時,請確保您具有管理員權限,並且已正確連接到主機板的 IPMI 接口。

  • 調整風扇轉速時,請密切關注系統溫度,確保不會因過度降低風扇轉速而導致硬體過熱。

  • 不同的 Supermicro 主機板型號可能存在差異,建議參考您的主機板使用手冊或官方文檔以獲取更多詳細資訊。