Try   HackMD

lab0-c

tags: sysprog2020

by <owlfox>

TOC

  1. Implementation of CMU Lab0 part
  2. sort, natural sort
  3. valgrind
  4. Dude
  5. select/console.c

Implementation

I am also practicing how to use catch2 and cmake, and will incorporate test driven style into this assignment.

catch2 is added through gitmodule, I used the single include header so that we don't have to build/install the library.
A few unit testing related files are in tests directory.

To run the tests:

mkdir build && cd build
cmake ..
cmake --build . && ./queue_unit
./queue_unit -h # list available cmd with catch2

q_new

Create a new, empty queue.

qfree

Free all storage used by a queue.

  • qinserthead:Attempt to insert a new element at the head of the queue (LIFO discipline).

  • qinserttail:Attempt to insert a new element at the tail of the queue (FIFO discipline).

  • qremovehead:Attempt to remove the element at the head of the queue.

  • qsize:Compute the number of elements in the queue.

  • qreverse:Reorder the list so that the queue elements are reversed in order. This function should notallocate or free any list elements (either directly or via calls to other functions that allocate or free listelements.) Instead, it should rearrange the existing elements.

  • qsort:

TODO:

  • port all the test cmds to catch2
  • tagging different cases

作業要求

詳細閱讀 C Programming Lab ,依據指示著手修改 queue.[ch] 和連帶的檔案,測試後用 Git 管理各項修改,記得也該實作 q_sort 函式。

修改排序所用的比較函式,變更為 natural sort,在 “simulation” 也該做對應的修改,得以反映出 natural sort 的使用。
除了修改程式,也要編輯「作業區」,增添開發紀錄和 GitHub 連結,除了提及你如何逐步達到自動評分程式的要求外,共筆也要涵蓋以下:

​​​​運用 Valgrind 排除 qtest 實作的記憶體錯誤,並透過 Massif 視覺化 “simulation” 過程中的記憶體使用量,需要設計對應的實驗
​​​​研讀論文 Dude, is my code constant time?,解釋本程式的 “simulation” 模式是如何透過以實驗而非理論分析,達到驗證時間複雜度,需要解釋 Student’s t-distribution 及程式實作的原理;
​​​​解釋 select 系統呼叫在本程式的使用方式,並分析 console.c 的實作,說明其中運用 CS:APP RIO 套件 的原理和考量點。可對照參考 CS:APP 第 10 章重點提示 :arrow_forward: 為避免「舉燭」,請比照 qtest 實作,撰寫獨立的終端機命令解譯器 (可建立新的 GitHub repository)