F01: lab0
主講人: jserv / 課程討論區: 2019 年系統軟體課程
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
返回「Linux 核心設計」課程進度表
作業說明直播錄影
預期目標
- 英文閱讀
- C 語言程式設計基礎
- 準備 GNU/Linux 開發工具
- 學習使用 Git 與 GitHub
- 學習效能分析
- 研究自動測試機制
Introduction to Computer Systems (ICS) 的第一份作業
CMU Introduction to Computer Systems (ICS) 準備了 C Programming Lab 作為檢閱學生 C 語言程式設計的認知:
- Explicit memory management, as required in C.
- Creating and manipulating pointer-based data structures.
- Working with strings.
- Enhancing the performance of key operations by storing redundant information in data structures.
- Implementing robust code that operates correctly with invalid arguments, including NULL pointers.
實驗目標為實作 queue
- first in, first out (FIFO)
- last in, first out (LIFO)
- 使用一致的 coding style 很重要,我們可透過 clang-format 這個工具來調整作業程式要求的風格為以下:
- 你可以想像 Apple 和 Google 的工程師隨便安置程式碼,然後不用管合作的議題嗎?
- 即便一個人寫作業,其實是三人的參與:過去的你、現在的你,以及未來的你
- 當首次執行
make
後,Git pre-commit hook 將自動安裝到現行的工作區 (workspace),之後每次執行 git commit
時,Git hook 會檢查 C/C++ 原始程式碼的風格是否一致:
- 我們介紹 Git hooks 是為了日後銜接 Continuous integration (CI),專業程式設計必備的準備工作
- 任何人都可以寫出機器看得懂的程式碼 (在檔案總管裡面對 EXE 檔複製貼上即可),但我們之所以到資訊工程系接受訓練,為了寫出人看得懂、可持續維護和改進的程式
- 下圖展示 Git pre-commit hook 偵測到開發者的修改並未遵守一致的 coding style,主動回報並提醒開發者:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
自動評分系統
qtest
執行檔內有包裝許多測試這次作業可用的工具,執行 qtest
後可打 help
即有各指令解說
qtest 使用範例:
如果什麼都沒做,當然是零分,參考輸出:
開發環境設定
- 依據 GNU/Linux 開發工具共筆 的指引,設定好 git, GitHub 帳號, vim (或其他你偏好的編輯器), perf, gnuplot
- 安裝以下開發工具
- 如果你之前尚未設定或使用過 GitHub 服務,請依循 GitHub 設定指引
Git 操作和 GitHub 使用示範
取得程式碼: (一旦你 fork 後,可將 sysprog21
換為你的 GitHub 帳號)
編譯:
預期會看到以下輸出:
事先編輯檔案 queue.h
後,執行 git commit
會發現:
原來要指定變更的檔案,用命令 git add
:
重新 git commit
,這時可發現安裝的 Git hooks 發揮作用了:
Git hook 提示我們:
- 第 4 行輸入
e
,可編輯 git commit
的訊息
- 第 7 行輸入
y
,因為 y 不是有效選項, 所以出現 help
- 第 17 行輸入
e
, 再次編輯訊息,因訊息有限制標題開頭要大寫
commit 前再調整訊息,注意,請避免用 git commit -m
,而是透過編輯器調整 git commit message。
接著將本地端的修改同步 GitHub 上,執行 git push
: (下方的 butastur-rtos
是示範帳號,請換為你自己的 GitHub 帳號名稱)
牛刀小試,嘗試實作函式 q_size
。
int q_size(queue_t *q)
由於要在 的常數時間內執行完成, 所以也不可能每次都走訪整個 list 來取得 queue 的大小,
queue.h
的註解提到:
You will need to add more fields to this structure to efficiently implement q_size and q_insert_tail
因此,我們增加 int size 到 struct queue_t
:
接著修改 q_size
的傳回值, 改成傳回 q->size
, 一切就緒後,提交修改:
發現格式不對,所以 Git commit hook 擋住了,所以我們用 clang-format -i
去調整格式,才能繼續。
使用工具分析 q_reverse 的執行表現
用 valgrind
來檢查一下 qtest
的執行結果是否存在 memory leak
對 valgrind
多一些嘗試, 試一下 valgrind --leak-check=full
作業要求
- 在 GitHub 上 fork lab0-c
- 詳細閱讀 C Programming Lab (英文閱讀正是我們想強化的議題,你應該在共筆上摘要題目要求),依據指示著手修改
queue.[ch]
和連帶的檔案,測試後用 Git 管理各項修改。
- 除了修改程式,也要編輯「作業區」,增添開發紀錄和 GitHub 連結,提及如何逐步達到要求,以及如何改善效能
- 解釋自動評分系統運作的原理
- 提及
qtest
的行為和裡頭的技巧
- 截止日期:
- Mar 3, 2019 (含) 之前
- 越早在 GitHub 上有動態、越早接受 code review,評分越高